
Do your blog gets a lot of comments? Here is an easy way to know the average comments per posts on your WordPress blog, using new functions introduced in WordPress 2.7.

Do your blog gets a lot of comments? Here is an easy way to know the average comments per posts on your WordPress blog, using new functions introduced in WordPress 2.7.
Simply paste the following code anywhere on your theme, where you'd like the average comments per post to be displayed:
<?php $count_posts = wp_count_posts(); $posts = $count_posts->publish; $count_comments = get_comment_count(); $comments = $count_comments['approved']; echo "Average ".round($comments/$posts)." comments per post."; ?>
This code is quite simple: First, we get the total number of published posts and the total number of approved comments. Once we have it, we just have to divide the number of comments by the number of posts.
19 Responses
That’s a really cool recipe!
Heh, simple math mixed with some php. Nice one.
Great ! Thx !
This recipe makes me sick of how inconsistently named Wordpress API is. As a programmer, who has had to enhance existing Wordpress site, I can say that Wordpress API is pretty incomprehensible…
I find that this worked quite well when I placed it in the sidebar, but it resulted in the blog post not showing up on the page.
How to display this information on the page?
Trackbacks: