Go Back   vb.org Archive > vBulletin 3 Discussion > vB3 General Discussions

Reply
 
Thread Tools Display Modes
  #1  
Old 02-03-2011, 01:47 PM
vivoperdio's Avatar
vivoperdio vivoperdio is offline
 
Join Date: Jun 2009
Location: Lajatico, Tuscany, Italy
Posts: 30
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default Displaying Total Posts & Members on Header

Hi, I would like to ask:

How to display total posts & members in header/navbar?

Example:


I tried to use the code below (taken from forumhome -> stats) but seems not working:

Code:
<div>
$vbphrase[threads]: $totalthreads,
$vbphrase[posts]: $totalposts,
$vbphrase[members]: $numbermembers<if condition="$show['activemembers']">,
<span title="<phrase 1="$vboptions[activememberdays]">$vbphrase[within_the_last_x_days]</phrase>">$vbphrase[active_members]: $activemembers</span>
</if>
</div>
Any idea?

Thank you and I hope to hear a good response from you soon.
Reply With Quote
  #2  
Old 02-03-2011, 03:45 PM
BirdOPrey5's Avatar
BirdOPrey5 BirdOPrey5 is offline
Senior Member
 
Join Date: Jun 2008
Location: New York
Posts: 10,610
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Those values are only calculated on the forum index (forumhome) page so on any other page they will all be blank.

If you want to put them in your navbar you'll need to make a new plugin do do those queries on each page and display their output- you'll also want to rename the variables so you don't conflict with the existing variable names.
Reply With Quote
  #3  
Old 02-03-2011, 09:51 PM
vivoperdio's Avatar
vivoperdio vivoperdio is offline
 
Join Date: Jun 2009
Location: Lajatico, Tuscany, Italy
Posts: 30
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Can you make one for me? I'm willing to offer you a paid service for this if you wish, just PM me your query
Reply With Quote
  #4  
Old 02-04-2011, 01:10 AM
BirdOPrey5's Avatar
BirdOPrey5 BirdOPrey5 is offline
Senior Member
 
Join Date: Jun 2008
Location: New York
Posts: 10,610
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Sorry, I tried working on this for a while... I found some suggestions in this thread:
https://vborg.vbsupport.ru/showthread.php?t=77916

But nothing I tried worked.
Reply With Quote
  #5  
Old 02-04-2011, 10:05 PM
vivoperdio's Avatar
vivoperdio vivoperdio is offline
 
Join Date: Jun 2009
Location: Lajatico, Tuscany, Italy
Posts: 30
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Thank you for your reference, m8.. Let's get it worked
Reply With Quote
  #6  
Old 02-05-2011, 12:09 AM
kh99 kh99 is offline
 
Join Date: Aug 2009
Location: Maine
Posts: 13,185
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

I think this works:

Code:
cache_ordered_forums(1, 1);
$totalthreads = 0;
$totalposts = 0;
if (is_array($vbulletin->forumcache))
{
	foreach ($vbulletin->forumcache AS $forum)
	{
		$totalthreads += $forum['threadcount'];
		$totalposts += $forum['replycount'];
	}
}
$totalthreads = vb_number_format($totalthreads);
$totalposts = vb_number_format($totalposts);
using global start. You might want to change the variable names like BOP5 mentioned. The call to cache_ordered_forums() fills some of the cache fields, and calling it here means it will be done twice on some pages, [S]but it doesn't look like that includes any of the main pages like showthread or forumdisplay so maybe it's OK[/S] (see my later post).

For the total members you could do a query:

Code:
$members = $vbulletin->db->query_first("SELECT COUNT(*) AS users 
                                        FROM " . TABLE_PREFIX . "user");
$numbermembers = $members['users'];

The value is in the datastore but to get it you'd have to add userstats to $specialtemplates before including global.php (like is mentioned at the link BOP5 posted above), but that would mean editing the file for every page you wanted it to appear on, or maybe putting it in init.php (although I'm not sure what other issues that might cause).
Reply With Quote
  #7  
Old 02-05-2011, 01:22 AM
BirdOPrey5's Avatar
BirdOPrey5 BirdOPrey5 is offline
Senior Member
 
Join Date: Jun 2008
Location: New York
Posts: 10,610
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

kh99 was spot on as usual.

To put this all together go to your Admin CP -> plugin manager -> add new plugin
product: vBulletin
hook: global_start
title: Stats on Navbar
Execution Order: 5
php code:
PHP Code:
$specialtemplates = array('userstats');  

require_once(
'global.php');

cache_ordered_forums(11);
$boptotalthreads 0;
$boptotalposts 0;
if (
is_array($vbulletin->forumcache))
{
    foreach (
$vbulletin->forumcache AS $bopforum)
    {
        
$boptotalthreads += $bopforum['threadcount'];
        
$boptotalposts += $bopforum['replycount'];
    }
}

    
$bopthreads vb_number_format($boptotalthreads); 
    
$bopposts vb_number_format($boptotalposts);

$bpmembers $vbulletin->db->query_first("SELECT COUNT(*) AS users 
                                        FROM " 
TABLE_PREFIX "user");
$bopmembers $bpmembers['users']; 
Set Active to YES and hit save.

Then in your navbar you can use $bopposts, $bopthreads, and $bopmembers which will hold the number os posts, threads, and members respectfully.

Note however this adds extra queries to your pages but there's no other way to get this info if you want it on every page.
Reply With Quote
  #8  
Old 02-05-2011, 12:46 PM
kh99 kh99 is offline
 
Join Date: Aug 2009
Location: Maine
Posts: 13,185
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Quote:
Originally Posted by kh99 View Post
The call to cache_ordered_forums() fills some of the cache fields, and calling it here means it will be done twice on some pages, but it doesn't look like that includes any of the main pages like showthread or forumdisplay so maybe it's OK.)
Actuall I have to take that back: it *is* called in forumdisplay, and if you're using the original index.php it's called there as well. So on a busy site where you're worried about every query, you may want to be careful about using this.
Reply With Quote
  #9  
Old 03-17-2011, 03:44 PM
vivoperdio's Avatar
vivoperdio vivoperdio is offline
 
Join Date: Jun 2009
Location: Lajatico, Tuscany, Italy
Posts: 30
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Hi, thank's for your help (both kh99 and BOP5)
I have a question, what if I don't change the variable names?
Reply With Quote
  #10  
Old 03-17-2011, 05:40 PM
BirdOPrey5's Avatar
BirdOPrey5 BirdOPrey5 is offline
Senior Member
 
Join Date: Jun 2008
Location: New York
Posts: 10,610
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

You can use the $bop variables just fine... if you use just $threads and $posts and such it might interfere with other mods or regular board functions, it's just a good idea to use unique names.
Reply With Quote
Reply

Thread Tools
Display Modes

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 10:21 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.05142 seconds
  • Memory Usage 2,253KB
  • Queries Executed 13 (?)
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
  • (1)bbcode_php
  • (1)bbcode_quote
  • (1)footer
  • (1)forumjump
  • (1)forumrules
  • (1)gobutton
  • (1)header
  • (1)headinclude
  • (1)navbar
  • (3)navbar_link
  • (120)option
  • (1)pagenav
  • (1)pagenav_curpage
  • (2)pagenav_pagelink
  • (10)post_thanks_box
  • (10)post_thanks_button
  • (1)post_thanks_javascript
  • (1)post_thanks_navbar_search
  • (10)post_thanks_postbit_info
  • (10)postbit
  • (10)postbit_onlinestatus
  • (10)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_postinfo_query
  • fetch_postinfo
  • 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
  • pagenav_page
  • pagenav_complete
  • tag_fetchbit_complete
  • forumrules
  • navbits
  • navbits_complete
  • showthread_complete