Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

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

share|improve this question
add comment

2 Answers

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()
share|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
add comment
<?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

share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.