Quick Tip: Display Total Number of Blog Comments

in WordPress Tutorials
Easy WordPress tutorial videos for beginners.

A lot of blogs are displaying social media followers and network links as a count on the main page. It serves as a good measure of how popular the blog or website has become.

But a lot of blogs forget the internal community or reader comments. A popular blog always has a lot of comments under each post as readers discuss points of view and information with the author.

So instead of displaying the total number of social media followers and social network links it might be a great idea to display the total number of comments that exist on the blog or site in question.

Display Number of Blog Comments

Before continuing, the next step requires proper FTP access to the related blog or website so this feature can only be implemented by the blog owner or a site admin.

The following code can be implemented by using the integrated WordPress theme and HTML editor but IS NOT compatible with the widgets feature.

Place the following segment of code where you would like the comment counter to appear:

<?php
$numcomms = $wpdb->get_var("SELECT COUNT(*) FROM $wpdb->comments WHERE comment_approved = '1'");
if (0 < $numcomms) $numcomms = number_format($numcomms);
echo "".$numcomms." total blog comments";
?>

Of course this code can be customized and spruced up to be a little more visual, but ultimately it will just output a text based counter of the total blog comments.

A more direct example of the code in action can be seen below.

Total Number of Blog Comments

All finished! You should now be rewarded with an accurate ticker of total blog comments.

Easy WordPress tutorial videos for beginners.

Comments (2)

Easy WordPress tutorial videos for beginners.
  • Comment by eddry0
    eddry0
    says:

    useful but only for a blog that have lot of comments. Thank’s anyway

  • Comment by Jake Bower
    Jake Bower
    says:

    thanks for the useful post
    but did you know that http://www.atthebull.com has better information?

Easy WordPress tutorial videos for beginners.