Some days ago, I shown you a great hack about getting the total number of posts published on your WordPress blog. Today, let’s do the same with comments.
This simple hack works exactly as the “get total number of posts” hack works: We’re using the $wpdb object and make a custom query to MySQL:
<?php $numcomms = $wpdb->get_var("SELECT COUNT(*) FROM $wpdb->comments WHERE comment_approved = '1'"); if (0 < $numcomms) $numcomms = number_format($numcomms); ?>
Right now, the $numcomms variable contains the total number of comments posted on your WordPress blog. To display this number, simply do something like:
<?php echo "There's ".$numcomms." comments on this blog";