Display your average comments per wordpress posts

February 9, 2009 · Print This Article

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:

$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.

Your choice for site templates and wordpress themes


Got something to say?

You must be logged in to post a comment.