Home / comment / List top commentators
  • How to List top commentators

    no thumbnail sorry: List top commentators

    Adding the first block of PHP code to the functions.php of your wordpress theme will let you call the function in the bellow block of code anywhere in your theme to display the top five commentators.

    ( click code to copy )

    wordpress snippet : PHP - functions.php

    <>
    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;
    }
    
    ( click code to copy )

    wordpress snippet : PHP

    <>
    <?
             top_comment_authors();
    ?>
    

    ( WordPress codex functions, hooks, in this snippet. )

    author_email, comment_author, _e, wp,