vb.org Archive

vb.org Archive (https://vborg.vbsupport.ru/index.php)
-   vB3 General Discussions (https://vborg.vbsupport.ru/forumdisplay.php?f=111)
-   -   Displaying Total Posts & Members on Header (https://vborg.vbsupport.ru/showthread.php?t=258284)

vivoperdio 02-03-2011 01:47 PM

Displaying Total Posts & Members on Header
 
Hi, I would like to ask:

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

Example:
https://vborg.vbsupport.ru/

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.

BirdOPrey5 02-03-2011 03:45 PM

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.

vivoperdio 02-03-2011 09:51 PM

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 :)

BirdOPrey5 02-04-2011 01:10 AM

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. :(

vivoperdio 02-04-2011 10:05 PM

Thank you for your reference, m8.. Let's get it worked :D

kh99 02-05-2011 12:09 AM

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).

BirdOPrey5 02-05-2011 01:22 AM

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.

kh99 02-05-2011 12:46 PM

Quote:

Originally Posted by kh99 (Post 2158902)
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.

vivoperdio 03-17-2011 03:44 PM

Hi, thank's for your help (both kh99 and BOP5)
I have a question, what if I don't change the variable names?

BirdOPrey5 03-17-2011 05:40 PM

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.

vivoperdio 03-18-2011 08:26 AM

Quote:

Originally Posted by BirdOPrey5 (Post 2174466)
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.

is this plug-in modifies database?

BirdOPrey5 03-18-2011 11:31 AM

No, no database modification. Just adds a query (reads from the database.)

vivoperdio 03-18-2011 12:24 PM

Thank you for your help, BOP5.. Have a great day always :)

vivoperdio 04-13-2011 10:07 AM

I used "$bopposts, $bopthreads, and $bopmembers" but not running:

https://vborg.vbsupport.ru/external/2011/04/28.png

BirdOPrey5 04-13-2011 06:14 PM

Are you sure you set "Active" to "Yes" in the plugin before saving it?

medicalforums 04-13-2011 09:40 PM

There's a mod for that. I use it and I have no problems.
Here's the link
https://vborg.vbsupport.ru/showthread.php?t=128863

vivoperdio 04-14-2011 12:30 AM

Hi there, medicalforums thanks for your advice :)

LoL.. I never used a plug-ins before, so the whole plug-ins system is disabled from the vBulletin Options.. I've enabled that and now the plug-ins is working.. Thanks BOP5 :D

Btw, how to make the total member display have ',' ?

For example, current display: 100000
How to make it displays: 100,000 ?

BirdOPrey5 04-14-2011 05:36 PM

Add this line to the end of the plugin:

Code:

$bopmembers = vb_number_format($bopmembers);
Should format the number with commas or periods or whatever you have set in vbulletin settings.

vivoperdio 04-16-2011 08:54 AM

Thanks BOP5, all set now :D

vivoperdio 04-19-2011 06:47 AM

@BOP5: I just upgraded to vBulletin 4, will this code works with vBulletin 4 ?

BirdOPrey5 04-19-2011 02:48 PM

I don't know, the php code should probably work, won't hurt to try it.

You will have to re-do the changes to your templates for sure. You will also have to register the variables to the templates, and there is a new way or writing variables for display in templates.

One thing I would do is edit the plugin and change the hook from global_start to global_bootstrap_init_start. global_start isn't truly "global" in VB4.

As this is now a VB4 issue though please make a thread for further questions in the VB4 forums, maybe post a link to it here so I see it.

vivoperdio 04-23-2011 02:08 PM

confirmed: not working on vb4 :D


All times are GMT. The time now is 06:33 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.01130 seconds
  • Memory Usage 1,774KB
  • 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
  • (4)bbcode_code_printable
  • (1)bbcode_php_printable
  • (2)bbcode_quote_printable
  • (1)footer
  • (1)gobutton
  • (1)header
  • (1)headinclude
  • (6)option
  • (1)post_thanks_navbar_search
  • (1)printthread
  • (22)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