First put this snippet in your functions.php file inside your theme.
function top_comment_authors($amount = 5){
global $wpdb;
$results = $wpdb->get_results('
SELECT
COUNT(comment_author_email) AS comments_count, comment_author_email, comment_author, comment_author_url
FROM
'.$wpdb->comments.'
WHERE
comment_author_email != "" AND comment_type = "" AND comment_approved = 1
GROUP BY
comment_author_email
ORDER BY
comments_count DESC, comment_author ASC
LIMIT '.$amount
);
$output = "<ul>";
foreach($results as $result){
$output .= "<li>".$result->comment_author."</li>";
}
$output .= "</ul>";
echo $output;
}
Now you can call it anywhere in your theme using the top_comment_authors() function. By default it will show top 5 but if you want a different amount simply call it like top_comment_authors(7) which will show top 7 comment authors.
If you want to show more data in the listing you can use these:
- $result->comment_author_email the email address of the commentator
- $result->comments_count comments number of the commentator
- $result->comment_author_url the website address of the commentator
Our WordPress themes
We have a few WordPress themes that we would like you to take a look at if you want.
check out the portfolio











That’s fantastic, thank you Boba!
Once again, I have a suggestion to make: would it be possible to show commentators’ Gravatar?
It is great already, but it would be awesome if it was possible
Thank you!
Yeah, simply use the get_avatar() function. You can read more about it in the WordPress Codex.
Hi Boba, I hope everything is fine for you!
Do you think it would be possible to show top commentators by category ID? For example, I have a Photography category (ID 1) and a Video category (ID 2) and I would to show on my index page for Photography, top commentators who commented but only on posts from category ID 1.
Do you think this is something you can add to your code? Or maybe it is very complicated, I dunno…
PS: I wasn’t able to add avatars, I read the Codex but I wasn’t successful so I decided not to show them. Yes, I’m that bad in coding!
Thank you!
Yeah, everything is great
I just can’t find enough time for everything so it’s a bit quiet here, but that should change soon
I guess it’s possible with JOIN or something like that in the mySQL query but i’m not really experienced with that so it might take a while till i figure it out.
No problem, I understand, when you have time
By the way, since you were the only one to find how to increase the categories selection height in WordPress admin, I’ve got another challenge for you. I didn’t find the answer nowhere (WP forums, Google, WP hack websites…). Do you know how to remove the ‘Website’ in user profile? I could remove aim, etc but no way to remove ‘Website’.
Any idea is welcome, when you have time, as always
Thanks a lot Boba!
Nice Trick!
Is there any way to modify this code to Show Top Commentators from a particular category !
I’ve been trying to solve this but couldn’t figure out !
Can somebody guide/help me