Codeable info

Quick Tip: Display Total Number of Blog Comments

Posted on by in WordPress Tutorials

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:

$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.

Codeable info

Comments (2)

Comment by eddry0 says:

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

Comment by Jake Bower says:

thanks for the useful post
but did you know that has better information?

Codeable info