How to Display Total Number of Posts and Comments on Your Blog

How to Display Total Number of Posts and Comments on Your Blog

We all love numbers :D right? So, how about showing some statistics on your wordpress blog to attract visitors and let them show your blog in numbers.

Display Total Number of Posts in Wordpress:

<?php
$numposts = $wpdb->get_var("SELECT COUNT(*) FROM $wpdb->posts WHERE post_status = 'publish'");
if (0 < $numposts) $numposts = number_format($numposts);

echo 'We have published '.$numposts.' since our launch.';
?>

Display Total Number of Comments in Wordpress:

<?php
$numcomms = $wpdb->get_var("SELECT COUNT(*) FROM $wpdb->comments WHERE comment_approved = '1'");
if (0 < $numcomms) $numcomms = number_format($numcomms);

echo 'Our readers have made '.$numcomms.' comments so far.';
?>

Thanks to Jeff Starr for sharing this code.

Luis Fernando
March 31, 2010 5:34 AM

Thanks for sharing this info.

Leave a Reply