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