The Arcive of Official vBulletin Modifications Site.It is not a VB3 engine, just a parsed copy! |
|
#1
|
|||
|
|||
Displaying VB Variables in external page - particularly forum stats
Hi all, I am attempting to create a php file that displays my forum stats, to use as an include in a wordpress themplate.
So far I have the following code, saved as a file in my forum root directory: Code:
<?php require_once('./global.php'); echo {vb:raw numbermembers}; ?> Can anyone help? |
#2
|
|||
|
|||
The {vb:raw numbermembers} is something that can only be used in vbulletin templates. You could do something like echo $numbermembers, but you need to calculate $numbermembers first. If you look in forum.php and search for "BOARD STATISTICS" you can find the section that calculates it.
Also, for that code to work you would need to get the 'userstats' loaded from the datastore, so you'd need Code:
$specialtemplates = array('userstats'); before you include global.php. Edit: now that I look at it more, there isn't much of a calculation for numbermembers, it just formats the number. |
Благодарность от: | ||
eviljoker7075 |
#3
|
|||
|
|||
What an incredibly helpful answer, thanks you! So I have the following working code, that gives me the total number of members:
Code:
<?php $specialtemplates = array('userstats'); require_once('./global.php'); $numbermembers = vb_number_format($vbulletin->userstats['numbermembers']); echo $numbermembers; ?> However, I also want to add in the total number of posts and threads, so I tried the below: Code:
<?php $specialtemplates = array('userstats'); $specialtemplates = array('forumcache'); require_once('./global.php'); $numbermembers = vb_number_format($vbulletin->userstats['numbermembers']); echo $numbermembers; $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); echo $totalthreads; echo $totalposts; ?> Thanks |
#4
|
|||
|
|||
The forum info always gets loaded, so you don't have to include that in $specialtemplates (in fact you really want to remove that second $specialtemplates line because it's overwriting what the first one does). But the forumcache doesn't include the thread and post count info. There's another function that adds that info, called cache_ordered_forums(). So if you add a call to that function like:
Code:
cache_ordered_forums(1, 1); after global.php is included and before you do the calculations, then it should work. |
#5
|
|||
|
|||
Perfect! Thank you very much. For anyone also wishing to do the same,
HERE IS THE FINAL WORKING CODE: File: 'forumStats.php' - saved in the root directory of my forum Code:
<?php $specialtemplates = array('userstats'); require_once('./global.php'); cache_ordered_forums(1, 1); $numbermembers = vb_number_format($vbulletin->userstats['numbermembers']); echo 'Members: '; echo $numbermembers; $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); echo ' Thread: '; echo $totalthreads; echo ' Posts: '; echo $totalposts; ?> However (there's always a but, right), when I add this as an include on my website homepage (running wordpress) I get an error. I have placed the following line into my template: PHP Code:
Quote:
|
#6
|
|||
|
|||
You're right. Try this for the beginning of the code:
Code:
<?php $specialtemplates = array('userstats'); chdir('./forum'); require_once('./global.php'); cache_ordered_forums(1, 1); If you wanted you could chdir() to the absolute path instead. And also you could save the current directory and chdir back after including gobal.php, but if that's the entire code then it doesn't look like it's necessary. |
#7
|
|||
|
|||
That did the trick nicely! Thank you so much for your help, I've learnt a lot.
|
|
|
X vBulletin 3.8.12 by vBS Debug Information | |
---|---|
|
|
More Information | |
Template Usage:
Phrase Groups Available:
|
Included Files:
Hooks Called:
|