23 Dec, 2003
Yearly Comment Leader Script
Posted by: Jennifer In: MT hacks
I just implemented the comment leaderboard script available here, but I wanted to feature the *yearly* comment leaders as opposed to the monthlies. I tinkered with it and lo and behold, it actually worked!
Replace the bold text with your own paths, e-mail address, author name, and blog id. You can adjust the number of leaders shown as well; the default is ten. You'll need the connect.php file in order for this script to work — info is available at The Girlie Matters.
<? include ("/PATH/TO/YOUR/FILE/connect.php");
$leaders = mysql_query("SELECT comment_email, comment_url, comment_author, COUNT(*) as comment_count FROM mt_comment WHERE (comment_blog_id=1) AND (comment_email !='E-MAIL ADDRESS YOU USE ON YOUR BLOG' AND comment_author !='NAME YOU USE ON YOUR BLOG') AND YEAR(comment_created_on) = YEAR(CURDATE()) GROUP BY comment_author, comment_email ORDER BY comment_count DESC LIMIT 10");
while($row = mysql_fetch_array($leaders)) {
while (list($key,$val) = each($row)) {$$key = $val;}
if (!empty($comment_url)) {
$authorlink = "<a href=\"$comment_url\">$comment_author</a>";
} elseif(!empty($comment_email)) {
$authorlink = "<a href=\"mailto:$comment_email\">$comment_author</a>";
} else {$authorlink = $comment_author;}
echo "$authorlink — $comment_count comments this year<br />\n";
}
?>