PDA

View Full Version : $totalposts


apinner
02-14-2009, 05:06 PM
I am hoping someone can help me out, i have searched around and could not find an answer.

I am using the $totalposts variable in my theme to display the current total posts for the forum which works just fine when viewing the forum index. However, when i go in and view a thread it shows how many posts there are in that thread and not the entire forum.

I want it to show the total posts of the entire forum on every page, what can i do? :confused:

Thanks in advance! :)

Voltar
02-14-2009, 07:02 PM
I have a theme with stats in the header on one of my forums, total posts being one of them.

Create a plugin, hook being global_start, name it whatever you want. Code:

$tpostq = $db->query_first("SELECT COUNT(postid) AS posts, COUNT(threadid) AS threads FROM " . TABLE_PREFIX . "post");
$tposts = number_format($tpostq['posts']);

Then in your template, use the $tposts variable for the stats. I'm pretty sure that'll do it.

Ted S
02-14-2009, 11:56 PM
While that option will work there's no need to use a query (and add to the server load) to get this stat.

The following attached will do just fine (or use the code below and create a plugin for global_start).


require_once(DIR . '/includes/functions_forumlist.php');
cache_ordered_forums(1, 1);

$totalthreads = 0;
$totalposts = 0;
if (is_array($vbulletin->forumcache))
{
echo "yup";

foreach ($vbulletin->forumcache AS $forum)
{
$totalthreads += $forum['threadcount'];
$totalposts += $forum['replycount'];
}
}

$totalthreads = vb_number_format($totalthreads);
$totalposts = vb_number_format($totalposts);