chat_bubble0 13 Aug 2017
Development Tutorials

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

 

 

 

 


Notice: ob_end_flush(): failed to send buffer of zlib output compression (0) in /home/dartthemes/public_html/wp-includes/functions.php on line 4669