Shows within the last 30 days.
Code:
<?
require("global.php");
$foruminfo=$DB_site->query("SELECT forumid, title FROM forum ORDER BY categoryid,displayorder");
while ($forum=$DB_site->fetch_array($foruminfo)) {
echo ("<a href=\"forumdisplay.php?forumid=".$forum[forumid]."\">".$forum[title]."</a><br>");
$threadinfo=$DB_site->query_first("SELECT threadid,title,replycount,views FROM thread WHERE forumid=$forum[forumid] and dateline > UNIX_TIMESTAMP(curdate()-30) ORDER BY views DESC LIMIT 1");
echo (" <a href=\"showthread.php?threadid=".$threadinfo[threadid]."\">".htmlspecialchars($threadinfo[title])."</a> [views: ".$threadinfo[views]."] [replies: ".$threadinfo[replycount]."]<br>");
}
?>
Demo:
http://sitepointforums.com/mostviewed.php
If you want to exclude certain forums. i.e. moderator forums, then add a WHERE clause to $foruminfo... For example:
WHERE forumid<>1