Display the Comment Stats on Your Advertising Page in WordPress

Posted on August 3rd, 2009 by in Tutorials | 2 Comments  
Display the Comment Stats on Your Advertising Page in WordPress

We can see the number of comments made in our dashboard, but our advertisers cannot see that. If you have a page for advertisers, you want to add this number to give them one more reason to buy advertisement on your site. Specially when you are selling ads towards the comment area.

Good Bye Mystery Man

All you have to do is paste the following code in a page where you want it displayed:

<?php
$count_posts = wp_count_posts();
$posts = $count_posts->publish;

$count_comments = get_comment_count();
$comments = $count_comments['approved'];

echo "There's a total of ".$comments." comments on my blog, with an average ".round($comments/$posts)." comments per post.";
?>

This code will tell your advertisers or your audience, how many total comments your blog has, and an average number of comments on each post. Sometimes the per post number might be a decimal, but this code rounds it up to an integer value.

You can also show this number in your sidebar as a statistic if you so desire.

About

Editorial Staff at WPBeginner mainly Syed and David.

Post comment as twitter logo facebook logo
Sort: Newest | Oldest
Tweets about us: