(+84) 463.28.7979

How to Display the Total Number of Comments in WordPress

Have you ever seen sites that show off their total RSS subscribers count, twitter follower count, and other vanity counts? Well let’s add one more to that list. Total comment counts. If you have a very engaged community, then it is a great idea to show off the total number of comments in your WordPress sidebar.

All you have to do is open your sidebar.php file, and paste the following code:

$commcount = $wpdb->get_var("SELECT COUNT(*) FROM $wpdb->comments WHERE comment_approved = '1'");
if (0 < $commcount) $commcount = number_format($commcount);
echo "Our users have made ".$commcount." comments, care to join in?";

Feel free to style the code in any way you like. Let us know if you have any questions.

Leave a Reply

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

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>