vb.org Archive

vb.org Archive (https://vborg.vbsupport.ru/index.php)
-   vB4 General Discussions (https://vborg.vbsupport.ru/forumdisplay.php?f=251)
-   -   totalposts in header (https://vborg.vbsupport.ru/showthread.php?t=294099)

omer3020 01-19-2013 05:32 AM

totalposts in header
 
hi,
how can i display {vb: totalposts} in the header template?

ty :)

--------------- Added [DATE]1358591472[/DATE] at [TIME]1358591472[/TIME] ---------------

????

kh99 01-19-2013 12:12 PM

Try this: create a new plugin using hook parse_template and this code:

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 [DATE]1358688103[/DATE] at [TIME]1358688103[/TIME] ---------------

???

omer3020 01-22-2013 05:40 AM

???

kh99 01-22-2013 12:33 PM

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:

Code:

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.


All times are GMT. The time now is 01:19 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.00991 seconds
  • Memory Usage 1,717KB
  • 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
  • (2)bbcode_code_printable
  • (1)footer
  • (1)gobutton
  • (1)header
  • (1)headinclude
  • (6)option
  • (1)post_thanks_navbar_search
  • (1)printthread
  • (5)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