Easily Add WordPress Top Comment Counter Without Plugin

One of the great way to show respect and encourage your blog reader is to show top comment counter in sidebar or in footer section. In comment count section you can list out who is on top of comment list. You can do this by many plugins. But you can also easily add WordPress top comment counter without plugin by adding a simple function in your theme. To add this function your theme widget’s have to accept PHP code. In our previous post we have show you how to allow PHP code in widget area. After allowing PHP in widget area first of all add the following code in your theme’s functions.php file:



function top_comment_authors($amount = 10){
global $wpdb;
$results = $wpdb->get_results(‘
COUNT(comment_author_email) AS comments_count, comment_author_email, comment_author, comment_author_url
comment_author_email != "" AND comment_type = "" AND comment_approved = 1
comments_count DESC, comment_author ASC
LIMIT ‘.$amount
$output = "<ul>";
foreach($results as $result){
$output .= "<li>".$result->comment_author."</li>";
$output .= "</ul>";
echo $output;


Here $amount=10 means in list maximum 10 commentors will be shown. If you want more or less then just change the number. After that go to widgets area and take the text widget and place the following code:


<?php top_comment_authors();?>



Place the text widget wherever you like. In our theme we have placed it in sidebar and here is the output:




Author: mytutorialguru

Share This Post On

Submit a Comment

Your email address will not be published. Required fields are marked *