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.

  • Share/Bookmark

,

43 Reviews

  1. 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….

  2. [...] Display the Total Number of Comments on Your WordPress Blog – PHP Magic Book [...]

  3. [...] need to find appropriate place in your blog and paste the code. Here’s how you can display number of comment and trackback 6. Put Avatar On Your Comments – Gravatar/MyBlogLog/Twitter [...]

  4. [...] 6. MOSTRAR O NÚMERO DE COMENTÁRIOS NO SEU BLOG As mostras de popularidade são uma forma eficiente de fazer o seu blog crescer ainda mais. Se por ventura recebe muitos comentários regularmente no seu blog, aprenda a apresentar esses números de forma dinâmica. [...]

  5. [...] Displaying Total Number Of Comments, If you have a popular WordPress blog with good number of comments everyday, then wouldn’t it be nice to be able to display the total number of comments published on your WordPress blog since your blog launch? The kind of stuff advertisers totally enjoy. [...]

  6. Thanks for your help on the comment feature using WordPress.

    Tony

  7. 12 sever says:

    [...] 3.Display the Total Number of Comments on Your WordPress Blog [...]

  8. [...] for PhpMagicBook for coming up with an easy way of showing the total number of [...]

  9. [...] 1) Display the Total Amount of Comments on Your Blog [...]

  10. [...] 1) Display the Total Amount of Comments on Your Blog [...]

  11. [...] 1) Display the Total Amount of Comments on Your Blog [...]

  12. [...] 1) Display the Total Amount of Comments on Your Blog [...]

  13. [...] 1- Blogunuzdaki Toplam Yorum Sayısını Gösterin [...]

  14. [...] 1- Blogunuzdaki Toplam Yorum Sayısını Gösterin [...]

  15. [...] 1- Blogunuzdaki Toplam Yorum Sayısını Gösterin [...]

  16. [...] 1- Blogunuzdaki Toplam Yorum Sayısını Gösterin [...]

  17. Hey thanks, nice! Good way to show off how popular your blog is by the comments.

  18. [...] 1) Display the Total Amount of Comments on Your Blog [...]

  19. ragi says:

    Good tut but I can’t stylize it. How can I make the numbers big and red?

  20. [...] Displaying Total Number Of Comments On Your Blog (or trackbacks) If you have a popular WordPress blog with good number of comments everyday, then wouldn’t it be nice to be able to display the total number of comments published on your WordPress blog since your blog launch? The kind of stuff advertisers totally enjoy. [...]

  21. [...] Displaying Total Number Of Comments On Your Blog (or trackbacks) If you have a popular WordPress blog with good number of comments everyday, then wouldn’t it be nice to be able to display the total number of comments published on your WordPress blog since your blog launch? The kind of stuff advertisers totally enjoy. [...]

  22. King says:

    @ragi: Just put all this code in a div block and give that div some style.

  23. [...] thanks to PHP Magic Book for this awesome code. Related Posts:-How to Display Twitter Count in Plain TextHow to Display [...]

  24. Durkin says:

    worked great and lets me thank all the readers and commentators, thanks!

  25. Edward Lane says:

    Super-Duper site! I am loving it!! Will come back again – taking your feeds too now, Thanks.

  26. kempozone says:

    Im 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!

  27. [...] Displaying Total Number Of Comments On Your Blog (or trackbacks) If you have a popular WordPress blog with good number of comments everyday, then wouldn’t it be nice to be able to display the total number of comments published on your WordPress blog since your blog launch? The kind of stuff advertisers totally enjoy. [...]

  28. FAQPAL Blog says:

    [...] Source… [...]

  29. [...] Displaying Total Number Of Comments On Your Blog (or trackbacks) If you have a popular WordPress blog with good number of comments everyday, then wouldn’t it be nice to be able to display the total number of comments published on your WordPress blog since your blog launch? The kind of stuff advertisers totally enjoy. [...]

  30. [...] Displaying Total Number Of Comments On Your Blog (or trackbacks) [...]

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

  32. [...] This snippet comes from Hiroshi at PHP Magic Book [...]

  33. [...] This snippet comes from Hiroshi at PHP Magic Book [...]

  34. [...] This snippet comes from Hiroshi at PHP Magic Book [...]

Leave a Review