PDA

View Full Version : Displaying forumstats in a sidebar block


WorldCraft
08-01-2013, 10:25 PM
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'
<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>

Created new PHP block
$templater = vB_Template::create('forumhome_forumstats');

$output = $templater->render();
return $output;

As expected it will display the HTML properly, but not the template variables. How can I access them? I'm new to using the $templater and am a bit stuck.

Thank you

kh99
08-02-2013, 06:23 PM
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:

global $vbulletin;

if (empty($vbulletin->userstats))
{
$vbulletin->datastore->fetch(array('userstats'));
}

// continue with code that uses userstats to calculate statistics

WorldCraft
08-03-2013, 07:29 PM
For some reason that code above breaks, and forumhome is just a white page.

Lynne
08-05-2013, 01:00 AM
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.

WorldCraft
08-05-2013, 03:24 AM
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.

I realize I don't use just that code...it's just that everything breaks when I use what was given above. I'll see if anything of use comes up in the error log.

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).

kh99
08-05-2013, 07:58 AM
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).

WorldCraft
08-05-2013, 10:41 PM
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! :)