vb.org Archive

vb.org Archive (https://vborg.vbsupport.ru/index.php)
-   vB3 Programming Discussions (https://vborg.vbsupport.ru/forumdisplay.php?f=15)
-   -   My odd project (https://vborg.vbsupport.ru/showthread.php?t=316645)

darnoldy 01-14-2015 03:35 AM

My odd project
 
Folks-

I'm trying to build something that's not-a-forum using vB3...

On the forum home page, I want to display two less threads than are actually in each forum (a long explanation, that I'm happy to skip).

The template variable, $forum[threadcount], gives me the actual count?but it appears that it is a string, rather than a value.

Is there any way that I can convert the variable to a value, perform an operation on it, convert the result back to a string?within the template?

--don

kh99 01-14-2015 07:02 PM

I guess it depends on the string format. If it automatically converts to the right integer then you might be able to do it (although I'm not certain offhand), otherwise you'd need to use a plugin.

nerbert 01-14-2015 08:10 PM

$threadcount = intval($forum[threadcount]);

kh99 01-14-2015 08:20 PM

Quote:

Originally Posted by nerbert (Post 2532558)
$threadcount = intval($forum[threadcount]);

Well, yeah, in a plugin. But you can't put that in a template. Also, if the number is formatted with a thousands separator (like a comma) then that will work until there are more than 1000 threads (I found this out the hard way with user post).

darnoldy 01-15-2015 03:06 AM

Quote:

Originally Posted by kh99 (Post 2532562)
if the number is formatted with a thousands separator (like a comma) then that will work until there are more than 1000 threads (I found this out the hard way with user post).

Guess I need to rethink my approach.

nerbert 01-15-2015 04:29 AM

Quote:

Originally Posted by kh99 (Post 2532562)
Well, yeah, in a plugin. But you can't put that in a template. Also, if the number is formatted with a thousands separator (like a comma) then that will work until there are more than 1000 threads (I found this out the hard way with user post).

But HTML doesn't do arithmetic!

Try this plugin for "forumbit_display"


Code:

$forum['threadcount'] = vb_number_format(intval($forum['threadcount']) - 2);

kh99 01-15-2015 05:30 AM

Quote:

Originally Posted by nerbert (Post 2532598)
But HTML doesn't do arithmetic!

Well, the OP says "within the template", so I took that to mean without a plugin. HTML can't do math but there are {vb:math ...} and {vb:number ...} template tags for doing simple arithmetic and formatting a number.


Quote:

Try this plugin for "forumbit_display"


Code:

$forum['threadcount'] = vb_number_format(intval($forum['threadcount']) - 2);

If the original value is already formatted with commas then you'd still have the issue I mentioned above.

nerbert 01-15-2015 12:40 PM

I don't see any practical way to do it in a template. Youre right about commas. This should catch it before it's formatted:
Code:

$forum['threadcount'] = vb_number_format(intval($counters["$forum[forumid]"]['threadcount']) - 2);
See line 367 functions_forumlist.php


All times are GMT. The time now is 02:10 AM.

Powered by vBulletin® Version 3.8.12 by vBS
Copyright ©2000 - 2025, vBulletin Solutions Inc.

X vBulletin 3.8.12 by vBS Debug Information
  • Page Generation 0.01070 seconds
  • Memory Usage 1,730KB
  • Queries Executed 10 (?)
More Information
Template Usage:
  • (1)ad_footer_end
  • (1)ad_footer_start
  • (1)ad_header_end
  • (1)ad_header_logo
  • (1)ad_navbar_below
  • (3)bbcode_code_printable
  • (5)bbcode_quote_printable
  • (1)footer
  • (1)gobutton
  • (1)header
  • (1)headinclude
  • (6)option
  • (1)post_thanks_navbar_search
  • (1)printthread
  • (8)printthreadbit
  • (1)spacer_close
  • (1)spacer_open 

Phrase Groups Available:
  • global
  • postbit
  • showthread
Included Files:
  • ./printthread.php
  • ./global.php
  • ./includes/init.php
  • ./includes/class_core.php
  • ./includes/config.php
  • ./includes/functions.php
  • ./includes/class_hook.php
  • ./includes/modsystem_functions.php
  • ./includes/class_bbcode_alt.php
  • ./includes/class_bbcode.php
  • ./includes/functions_bigthree.php 

Hooks Called:
  • init_startup
  • init_startup_session_setup_start
  • init_startup_session_setup_complete
  • cache_permissions
  • fetch_threadinfo_query
  • fetch_threadinfo
  • fetch_foruminfo
  • style_fetch
  • cache_templates
  • global_start
  • parse_templates
  • global_setup_complete
  • printthread_start
  • bbcode_fetch_tags
  • bbcode_create
  • bbcode_parse_start
  • bbcode_parse_complete_precache
  • bbcode_parse_complete
  • printthread_post
  • printthread_complete