total comment count for WordPress post

How to display total comment count for WordPress post

If you are running a popular blog website you will see lots of people are commenting on your post and responses are increasing significantly.  for the new visitor its very important to display how many people are participating on your post for comments to encourage them to participate too. simple way to display total comments counter in a higlighted area.

 

How to count total comment by post id?

WordPress has builtin function  wp_count_comments($post_id) for count comments by post ids. here is the all possible counts by comment status.

$comments_count = wp_count_comments($post_id);
echo "Comments for site <br />";
echo "Comments in moderation: " . $comments_count->moderated . "<br />"; 
echo "Comments approved: " . $comments_count->approved . "<br />";
echo "Comments in Spam: " . $comments_count->spam . "<br />";
echo "Comments in Trash: " . $comments_count->trash . "<br />";
echo "Total Comments: " . $comments_count->total_comments . "<br />";

 

If you want to display only approved comment count use this  $comments_count->approved