View Full Version : totalposts in header
omer3020
01-19-2013, 05:32 AM
hi,
how can i display {vb: totalposts} in the header template?
ty :)
--------------- Added 1358591472 at 1358591472 ---------------
????
Try this: create a new plugin using hook parse_template and this code:
global $vbulletin;
$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);
vB_Template::preRegister('header', array('totalthreads' => $totalthreads, 'totalposts' => $totalposts));
Then you should be able to use {vb:raw totalposts} in the header (I know you didn't ask for totalthreads, but it was there so I thought I'd just leave it).
omer3020
01-19-2013, 12:34 PM
It only works that I found in ForumHOME but when I entered the forum everything turns to 0 ...
And how to do it too to totalonline?
--------------- Added 1358688103 at 1358688103 ---------------
???
omer3020
01-22-2013, 05:40 AM
???
You're right, it doesn't work on all pages because the information isn't always in the forum cache. Sorry, my mistake. You could change the code to something like this:
global $vbulletin;
$totalthreads = 0;
$totalposts = 0;
if (is_array($vbulletin->forumcache))
{
foreach ($vbulletin->forumcache AS $forum)
{
$totalthreads += $forum['threadcount'];
$totalposts += $forum['replycount'];
}
}
if ($totalthreads == 0)
{
$result = $vbulletin->db->query_first_slave("SELECT SUM(threadcount) AS threadcount, SUM(replycount) AS replycount FROM " . TABLE_PREFIX . "forum");
if (!empty($result))
{
$totalthreads = $result['threadcount'];
$totalposts = $result['replycount'];
}
}
$totalthreads = vb_number_format($totalthreads);
$totalposts = vb_number_format($totalposts);
vB_Template::preRegister('header', array('totalthreads' => $totalthreads, 'totalposts' => $totalposts));
but you should be aware that this will add a query to each page that didn't already have the information, which could be significant if your forum is busy. It would be better to set something up to cache the information periodically, but that's a little more complicated.
vBulletin® v3.8.12 by vBS, Copyright ©2000-2025, vBulletin Solutions Inc.