Version: 1.00, by eXtremeTim
Developer Last Online: Feb 2008
Category: Forum Home Enhancements -
Version: 2.2.x
Rating:
Released: 08-19-2002
Last Update: Never
Installs: 7
No support by the author.
This hack counts the total thread hits for each forum then displays it where every you put the variable. This hack adds one querie per forum unless the forum has no posts in it then it doesn't add on for that forum. It also currently does not count sub forums. I plan to work on that soon.
global $forumviews;
$forumhits = $forumviews[$forum['forumid']];
if (intval($forumhits) < 1) {
$forumhits = 0;
}
now add the var $forumhits where you want the number of total views per forum to appear. this should only add 1 querry regardless of the number of forums.
once my server is back up, I'll be installing this.
You don't mention what files this hack needs to be placed in? Do I update the code in the index.php or fourmdisplay.php or both? Because "// Start makeforumbit" is listed in both of them in vB 2.2.8.
The best way of doing this imho is to have a "totalviews" column in the FORUM table. I keep updating this totalviews section on an hourly basis with a GROUPBY SQL similar to the one you use. It takes 0.0008 seconds on my server.
Now that this info is already in FORUM table, we can get this column along with the same SQL that gets all the other stuff.
In other words, there is *NO ADDITIONAL* query required.
Here is what I did:
1. Altered the "Forum" table to ADD an additional column:
"totalviews" (int(10))
2. Then, set up a cronjob to execute this code hourly (you can change timing to whatever you want of course) -- cron_update_forum_totalviews.php.txt. This code takes the total of all threads and puts them into the forum.
3. /includes/functions_forumlist.php
Find every occurence of replycount, and add the "totalviews" in a similar fashion. The attached /includes__functions_forumlist.php.txt file should tell you what I have added. Just search for the word replycount inside this file.
4. index.php
Find this code:
PHP Code:
if (is_array($forumcache))
This is the section where there are some references to "Replycount". I added stuff for "totalviews" so that my code looks like this:
PHP Code:
// get total threads & posts from the forumcache
$totalthreads = 0;
$totalposts = 0;
$totalviews = 0;
if (is_array($forumcache))
{
foreach ($forumcache AS $forum)
{
$totalthreads += $forum['threadcount'];
$totalposts += $forum['replycount'];
$totalviews += $forum['totalviews'];
}
}
$totalthreads = vb_number_format($totalthreads);
$totalposts = vb_number_format($totalposts);
$totalviews = vb_number_format($totalviews);
Of course, all changes are included in the attached index.php.txt
Hope this helps someone in the future include VIEWS on forumhome (forum's home page). Let me know how it works out. I have it in a BBS that's under a password protected website, so cannot show example, but works like a charm. No extra queries!