Beginner's Guide for WordPress - Start your WordPress Blog in minutes.
Choosing the Best
WordPress Hosting
How to Easily
Install WordPress
Recommended
WordPress Plugins
View all Guides

Display the Comment Stats on Your Advertising Page in WordPress

Last updated on by
Special WordPress Hosting offer for WPBeginner Readers
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.


Editorial Staff at WPBeginner is a team of WordPress experts led by Syed Balkhi. Page maintained by Syed Balkhi.

WPBeginner's Video Icon
Our HD-Quality tutorial videos for WordPress Beginners will teach you how to use WordPress to create and manage your own website in about an hour. Get started now »

Add a Comment

We're glad you have chosen to leave a comment. Please keep in mind that all comments are moderated according to our comment policy, and all links are nofollow. Do NOT use keywords in the name field. Let's have a personal and meaningful conversation.