Display the Total Number of Comments on Your WordPress Blog
In this tutorial we will learn how to show total number of comments at your blog using the $wpdb object. Use the following code where you want to display total number of comments at your blog.
<?php $numcomms = $wpdb->get_var("SELECT COUNT(*) FROM $wpdb->comments WHERE comment_approved = '1'"); if (0 < $numcomms) $numcomms = number_format($numcomms); ?>
Here $numcomms variable contains the total number of comments posted on your WordPress blog. To display this number, simply do something like:
<?php echo "There's ".$numcomms." total comments on my blog"; ?>
You can combine the code as well like following:
<?php $numcomms = $wpdb->get_var("SELECT COUNT(*) FROM $wpdb->comments WHERE comment_approved = '1'"); if (0 < $numcomms) $numcomms = number_format($numcomms); echo "There's ".$numcomms." total comments on my blog"; ?>
This should show you that how many comments your blog has got.

Tony @ free sports betting picks Says:
Thanks for your help on the comment feature using Wordpress.
Tony
Steve Patterson Says:
Hey thanks, nice! Good way to show off how popular your blog is by the comments.
ragi Says:
Good tut but I can’t stylize it. How can I make the numbers big and red?
King Says:
@ragi: Just put all this code in a div block and give that div some style.
Durkin Says:
worked great and lets me thank all the readers and commentators, thanks!
Edward Lane Says:
Super-Duper site! I am loving it!! Will come back again – taking your feeds too now, Thanks.
kempozone Says:
I‘m sure many of you are like me and one of the first things you do in the morning is head here and check out the new post. Along with seeing the new posts, I’m also always checking out the blog roll rss feed and watching them grow, or shrink sometimes. In one of my past …but all in all excellent site. Keep it up!
Trackback - Cheap Internation Call >> How to make cheap international call Says:
,..] http://www.phpmagicbook.com is other interesting source of tips on this issue,..]
Deepu Balan Says:
Thanks for the tip. But I want to show the total count of comments and trackbacks in the homepage. By default its showing only the comment count now. How can I do this?
Thanks in advance!
-Deepu