vb.org Archive

vb.org Archive (https://vborg.vbsupport.ru/index.php)
-   vB4 Programming Discussions (https://vborg.vbsupport.ru/forumdisplay.php?f=252)
-   -   Forum stats on a custom vb page? (https://vborg.vbsupport.ru/showthread.php?t=284967)

Da^MsT 06-27-2012 01:06 PM

Forum stats on a custom vb page?
 
I've set up a custom vb page, on this page I like to show, basically the same stats block as on forumhome. Got most of it working by checking forum.php, but 'totalposts' and 'totalthreads' only show 0 (zeros). What am I missing?

My custom page code:
PHP Code:

<?php

// ####################### SET PHP ENVIRONMENT ###########################
error_reporting(E_ALL & ~E_NOTICE);

// #################### DEFINE IMPORTANT CONSTANTS #######################

define('THIS_SCRIPT''wp-ext');
define('CSRF_PROTECTION'true);  
// change this depending on your filename

// ################### PRE-CACHE TEMPLATES AND DATA ######################
// get special phrase groups
$phrasegroups = array();

// get special data templates from the datastore
$specialtemplates = array(
    
'userstats',
    
'activeblocks',
);

// pre-cache templates used by all actions
$globaltemplates = array('wp-ext',
);

// pre-cache templates used by specific actions
$actiontemplates = array();

// ######################### REQUIRE BACK-END ############################
// if your page is outside of your normal vb forums directory, you should change directories by uncommenting the next line
// chdir ('/path/to/your/forums');
require_once('./global.php');

// #######################################################################
// ######################## START MAIN SCRIPT ############################
// #######################################################################

$navbits construct_navbits(array('' => 'To WP Ext'));
$navbar render_navbar_template($navbits);

// ###### YOUR CUSTOM CODE GOES HERE #####
$pagetitle 'WP Ext';

// ### BOARD STATISTICS #################################################

// get total threads & posts from the forumcache
$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);

// get total members and newest member from template
$numbermembers vb_number_format($vbulletin->userstats['numbermembers']);
$newuserinfo = array(
    
'userid'   => $vbulletin->userstats['newuserid'],
    
'username' => $vbulletin->userstats['newusername']
);
$activemembers vb_number_format($vbulletin->userstats['activemembers']);
$show['activemembers'] = ($vbulletin->options['activememberdays'] > AND ($vbulletin->options['activememberoptions'] & 2)) ? true false;

$ad_location['board_after_forums'] = vB_Template::create('ad_board_after_forums')->render();
$ad_location['board_below_whats_going_on'] = vB_Template::create('ad_board_below_whats_going_on')->render();


// ###### NOW YOUR TEMPLATE IS BEING RENDERED ######

$templater vB_Template::create('wp-ext');
$templater->register_page_templates();
  
$templater->register('navbar'$navbar);
  
$templater->register('pagetitle'$pagetitle);
  
$templater->register('activemembers'$activemembers);
  
$templater->register('activeusers'$activeusers);
  
$templater->register('ad_location'$ad_location);
  
$templater->register('newuserinfo'$newuserinfo);
  
$templater->register('numberregistered'$numberregistered);
  
$templater->register('numbermembers'$numbermembers);
  
$templater->register('template_hook'$template_hook);
  
$templater->register('totalposts'$totalposts);
  
$templater->register('totalthreads'$totalthreads);
print_output($templater->render());

?>

I'm trying to fetch the totals with

Code:

{vb:raw totalthreads}
{vb:raw totalposts}

Any suggestions?

kh99 06-27-2012 01:31 PM

Try calling
Code:

cache_ordered_forums(1, 1, $vbulletin->userinfo['userid']);

before your code that calculates the totals.

Da^MsT 06-28-2012 02:10 PM

Quote:

Originally Posted by kh99 (Post 2343295)
Try calling
Code:

cache_ordered_forums(1, 1, $vbulletin->userinfo['userid']);

before your code that calculates the totals.

Thank you very much, that did it :)


All times are GMT. The time now is 01:54 PM.

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.01076 seconds
  • Memory Usage 1,749KB
  • 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
  • (3)bbcode_code_printable
  • (1)bbcode_php_printable
  • (1)bbcode_quote_printable
  • (1)footer
  • (1)gobutton
  • (1)header
  • (1)headinclude
  • (6)option
  • (1)post_thanks_navbar_search
  • (1)printthread
  • (3)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