Go Back   vb.org Archive > vBulletin 3 Discussion > vB3 Programming Discussions
FAQ Community Calendar Today's Posts Search

Reply
 
Thread Tools Display Modes
  #1  
Old 01-14-2015, 03:35 AM
darnoldy darnoldy is offline
 
Join Date: Dec 2004
Posts: 234
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default 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
Reply With Quote
  #2  
Old 01-14-2015, 07:02 PM
kh99 kh99 is offline
 
Join Date: Aug 2009
Location: Maine
Posts: 13,185
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

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.
Reply With Quote
  #3  
Old 01-14-2015, 08:10 PM
nerbert nerbert is offline
 
Join Date: May 2008
Posts: 784
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

$threadcount = intval($forum[threadcount]);
Reply With Quote
  #4  
Old 01-14-2015, 08:20 PM
kh99 kh99 is offline
 
Join Date: Aug 2009
Location: Maine
Posts: 13,185
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Quote:
Originally Posted by nerbert View Post
$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).
Reply With Quote
  #5  
Old 01-15-2015, 03:06 AM
darnoldy darnoldy is offline
 
Join Date: Dec 2004
Posts: 234
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Quote:
Originally Posted by kh99 View Post
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.
Reply With Quote
  #6  
Old 01-15-2015, 04:29 AM
nerbert nerbert is offline
 
Join Date: May 2008
Posts: 784
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Quote:
Originally Posted by kh99 View Post
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);
Reply With Quote
  #7  
Old 01-15-2015, 05:30 AM
kh99 kh99 is offline
 
Join Date: Aug 2009
Location: Maine
Posts: 13,185
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Quote:
Originally Posted by nerbert View Post
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.
Reply With Quote
  #8  
Old 01-15-2015, 12:40 PM
nerbert nerbert is offline
 
Join Date: May 2008
Posts: 784
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

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
Reply With Quote
Reply


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT. The time now is 09:51 AM.


Powered by vBulletin® Version 3.8.12 by vBS
Copyright ©2000 - 2024, vBulletin Solutions Inc.
X vBulletin 3.8.12 by vBS Debug Information
  • Page Generation 0.04509 seconds
  • Memory Usage 2,231KB
  • Queries Executed 11 (?)
More Information
Template Usage:
  • (1)SHOWTHREAD
  • (1)ad_footer_end
  • (1)ad_footer_start
  • (1)ad_header_end
  • (1)ad_header_logo
  • (1)ad_navbar_below
  • (1)ad_showthread_beforeqr
  • (1)ad_showthread_firstpost
  • (1)ad_showthread_firstpost_sig
  • (1)ad_showthread_firstpost_start
  • (3)bbcode_code
  • (5)bbcode_quote
  • (1)footer
  • (1)forumjump
  • (1)forumrules
  • (1)gobutton
  • (1)header
  • (1)headinclude
  • (1)navbar
  • (3)navbar_link
  • (120)option
  • (8)post_thanks_box
  • (8)post_thanks_button
  • (1)post_thanks_javascript
  • (1)post_thanks_navbar_search
  • (8)post_thanks_postbit_info
  • (8)postbit
  • (8)postbit_onlinestatus
  • (8)postbit_wrapper
  • (1)spacer_close
  • (1)spacer_open
  • (1)tagbit_wrapper 

Phrase Groups Available:
  • global
  • inlinemod
  • postbit
  • posting
  • reputationlevel
  • showthread
Included Files:
  • ./showthread.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/functions_bigthree.php
  • ./includes/class_postbit.php
  • ./includes/class_bbcode.php
  • ./includes/functions_reputation.php
  • ./includes/functions_post_thanks.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
  • showthread_start
  • showthread_getinfo
  • forumjump
  • showthread_post_start
  • showthread_query_postids
  • showthread_query
  • bbcode_fetch_tags
  • bbcode_create
  • showthread_postbit_create
  • postbit_factory
  • postbit_display_start
  • post_thanks_function_post_thanks_off_start
  • post_thanks_function_post_thanks_off_end
  • post_thanks_function_fetch_thanks_start
  • post_thanks_function_fetch_thanks_end
  • post_thanks_function_thanked_already_start
  • post_thanks_function_thanked_already_end
  • fetch_musername
  • postbit_imicons
  • bbcode_parse_start
  • bbcode_parse_complete_precache
  • bbcode_parse_complete
  • postbit_display_complete
  • post_thanks_function_can_thank_this_post_start
  • tag_fetchbit_complete
  • forumrules
  • navbits
  • navbits_complete
  • showthread_complete