Count the number of comments on your WordPress blog

This article will guide you how to display the number of comments on your blog (of course those are approved comments) by a simple php code below.

1
2
3
4
5
6
<?php
global $wpdb;
$num_comments = $wpdb->get_var("SELECT COUNT(comment_ID) FROM $wpdb->comments WHERE comment_approved = '1'");
if ($num_comments > 0) $num_comments = number_format($num_comments);
echo "There are " . $num_comments . " comments on my blog";
?>
Paste the code to places you like in your theme's php files. And this is a live demo 
There are 1,172 comments on my blog
In the next article, I will guide you how to count the number of posts/pages on your blog. Remember to read!


1 nhận xét:

UB Webs said...

Web Application DevelopmentHire web Developer from UBWebs for Web Application Development PHP Mysql Developer Offshore IT Staffing Social Networking Customized Softwares Search Engine Optimisation Web Promotions Action Scripting Logo Designing Flash Designing Google Business App MS Small Business Application.

Post a Comment