The Arcive of Official vBulletin Modifications Site.It is not a VB3 engine, just a parsed copy! |
|
#1
|
|||
|
|||
Displaying forumstats in a sidebar block
Hello. I'm trying to move the Forum Statistics from What's Going On into a forum block. I read that it was possible to put the code in a template, and then just register the template in a PHP block. I'm there, but how to I access the variables in the template?
Here's my code Created new template called 'forumhome_forumstats' Code:
<dl> <dt>{vb:rawphrase threads}</dt> <dd>{vb:raw totalthreads}</dd><br /> <dt>{vb:rawphrase posts}</dt> <dd>{vb:raw totalposts}</dd><br /> <dt>{vb:rawphrase members}</dt> <dd>{vb:raw numbermembers}</dd><br /> <vb:if condition="$show['activemembers']"> <dt>{vb:rawphrase active_members}</dt> <dd>{vb:raw activemembers}</dd> </vb:if> </dl> Code:
$templater = vB_Template::create('forumhome_forumstats'); $output = $templater->render(); return $output; Thank you |
#2
|
|||
|
|||
Your php code need to include code to get and/or calculate whatever values you display. If you look at the file forum.php, you can find the code that calculates the values. I believe it depends on having 'userstats' in the $specialtemps array (near the top of the file). You would probably need to have something in your code to fetch it if it doesn't exist, so maybe something like:
Code:
global $vbulletin; if (empty($vbulletin->userstats)) { $vbulletin->datastore->fetch(array('userstats')); } // continue with code that uses userstats to calculate statistics |
#3
|
|||
|
|||
For some reason that code above breaks, and forumhome is just a white page.
|
#4
|
||||
|
||||
Then check your error_logs (if you don't know where they are, ask your host) and see what is there. But, you can't just use that code - you have to write a whole bunch of your own to go with it if you want the stats to display.
|
#5
|
|||
|
|||
Quote:
Edit: Just wanted to point out that $vbulletin->datastore->fetch(array('name')) breaks on two boards I work with (when using it in forum blocks). |
#6
|
|||
|
|||
Sorry about that, I hadn't tried that code at all, and there was a missing close paren which I've fixed, and it also needed a "global".
But thinking about it a little more, the forum block only appears on the home page which already loads the userstats, so you probably don't really need that code (unless you use a mod that puts the sidebar on other pages). You would need to declare $vbulletin as global (as in the first line of code I added above). |
#7
|
|||
|
|||
Got it working. All I was missing was the global. I had implied that was included automatically. Sorry about that...but thank you for the help!
|
|
|
X vBulletin 3.8.12 by vBS Debug Information | |
---|---|
|
|
More Information | |
Template Usage:
Phrase Groups Available:
|
Included Files:
Hooks Called:
|