PDA

View Full Version : Live Forum Statistics in Header Template


Neutral Singh
09-01-2005, 10:00 PM
Live Forum Statistics in Header Template
Should work in all vB 3.0.x series


I have absolutely no clue, who had originally written this bit of code as i only found this in a post somewhere, a long long times back (can't recollect). I would be more than glad to know the original writer of this useful code to give proper credit.

Requested by :
Myself images/newsm/devious.gif

Context :
Searched through vb.org but could not find a similar plugin/hack for vB3.5/vB3.0.x. I wanted to show all vital forum stats like total posts, total threads, total members and newest member on each page of my forum (http://www.sikhphilosophy.net/) as well as vBa CMPS, in header template and this plugin performs exactly the same function.

What this hack does ?
Stores the desired information from your forum database into php variables and when called in 'header 'template, produces the desired results.

Utility :
Imagine... an unregistered/guest visits your website for the first time via a search engine link (95% of times its not the homepage that is found via a search engines link) and the first thing s/he notices is the forum header information and says wow!! this forum has got xxxx members, xxxxx threads, xxxxxx posts, why not get registered with this community and see what this forum has got in store for me. LOL!! quite true actually. images/newsm/wink.gif

Demo : http://www.sikhphilosophy.net (http://www.sikhphilosophy.net/)

Any Screenshots : Demo is self-explanatory above.

Warning: This hack executes 5 queries per page.

Installation Instructions : (Also attached.)


Step by Step Instructions:

1. In the 'header' template:

Find: (ususally at the end of the template file)

<!-- content table -->
$spacer_open


Add Above:
<!-- Forum Stats in Header Template -->
<table width="100%" border="0" cellspacing="0" cellpadding="0">
<tr>
<td>
<div align="left">| Discussions: $totalthreads | Messages: $totalposts | Members: $numbermembers | Online: $totalonline | Newest :$newusername(Welcome!)
</span>
</td>
</tr>
</table>
<!-- Forum Stats in Header Template -->


Ofcourse you can customise this code to suit your website setup. ;)


2. In phpinclude_start template add the following code at the end.

// forum stats start
$numbersmembers=$DB_site->query_first("SELECT COUNT(*) AS users,MAX(userid) AS max FROM " . TABLE_PREFIX . "user");
$numbermembers=number_format($numbersmembers['users']);
$countposts=$DB_site->query_first("SELECT COUNT(postid) AS posts, COUNT(threadid) AS threads FROM " . TABLE_PREFIX . "post");
$totalposts=number_format($countposts['posts']);
$countthreads=$DB_site->query_first("SELECT COUNT(*) AS threads FROM " . TABLE_PREFIX . "thread");
$totalthreads=number_format($countthreads['threads']);
// forum stats end

// total online start
$datecut = TIMENOW - $vboptions['cookietimeout'];
$headerguests=$DB_site->query_first("SELECT COUNT(*) AS count FROM " . TABLE_PREFIX . "session WHERE userid=0 AND lastactivity>$datecut");
$headerusers=$DB_site->query_first("SELECT COUNT(DISTINCT(userid)) AS count FROM " . TABLE_PREFIX . "session WHERE " . TABLE_PREFIX . "session.userid>0 AND " . TABLE_PREFIX . "session.lastactivity>$datecut");
$headerguests=$headerguests[count];
$headerusers=$headerusers[count];
$totalonline=$headerguests+$headerusers;
// total online end

// get newest member name and userid start
$getnewestmember=$DB_site->query_first("SELECT userid, username FROM " . TABLE_PREFIX . "user WHERE " . TABLE_PREFIX . "userid=$numbersmembers[max]");
$newusername = $getnewestmember['username'];
$newuserid = $getnewestmember['userid'];
// get newest member name and userid end



And you are done!!

Please dont forget to click Install

Enjoy !!

Nordinho
09-02-2005, 05:09 PM
looks really good...I guess I need to disable the info at the bottom of forumhome to save some queries??

Koopa
09-03-2005, 07:02 PM
Looks good :) Nice one.

vakvak
09-04-2005, 01:41 AM
thanks

Thug
09-04-2005, 01:00 PM
nice work duno if i will use it yet

HHU
09-28-2005, 02:31 AM
Installed.. thanks

Actually, how would I create it so that you can click on the newest member and it will go to their userid profile page?

Neutral Singh
10-31-2005, 03:15 AM
** Template hack updated for forums using table_prefixes **

Enjoy !!