1

I would like to find out the number of comments in total I have and display the number on my website.

1

Hi @stubudz:

You are trying to make things easy on me today, right? :)

Here's what you need:

$comment_counts = get_comment_count();
echo $comment_counts['approved'];
//print_r($comment_counts); // Uncomment to see all from get_comment_count()
| improve this answer | |
  • 2
    Also wp_count_comments() ( source ), this one caches results which makes a difference if this needs to be fetched several times or persistent object cache is used. – Rarst Dec 27 '10 at 14:46
  • @Rarst - Good point. – MikeSchinkel Dec 27 '10 at 17:35
0
<?php
$numcomms = $wpdb->get_var("SELECT COUNT(*) FROM $wpdb->comments WHERE comment_approved = '1'");
if (0 < $numcomms) $numcomms = number_format($numcomms);
?>


There are <?php echo $numcomms; ?> in this blog.

source http://www.wprecipes.com/how-to-display-the-total-number-of-comments-on-your-wordpress-blog

| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy