Quick shooting stats of your Wordpress blog

Here’s a quick way to get and show some useful stats on your wordpress blog. This will show the number of posts,comments and categories you have to allow your visitors and yourself a broad view of your blog’s current state updated as these criteria change. By the end of this how-to, you would be displaying something like this:

quick shooting stats of your wordpress blog

So let’s start. Open either sidebar.php or footer.php from your current Wordpress theme’s folder depending on whether you want to display your quick stats in the sidebar thus sidebar.php or footer then footer.php. At the beginning of your sidebar/footer.php copy and paste the following lines of code :


<?php /* Counts the posts, comments and categories on your blog */
	$numposts = $wpdb->get_var("SELECT COUNT(*) FROM $wpdb->posts WHERE post_status = 'publish'");
	if (0 < $numposts) $numposts = number_format($numposts); 

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

	$numcats = $wpdb->get_var("SELECT COUNT(*) FROM $wpdb->categories");
	if (0 < $numcats) $numcats = number_format($numcats);

?>

Then move along the same template file - sidebar.php/footer.php and spot the place where you want your quick shooting stats to get displayed. Then copy and paste these lines where you want them to appear for your great audience.


There are currently <?php echo $numposts; ?> posts extending over <?php echo $numcats; ?> categories with loads upto <?php echo $numcomms; ?> comments.

That’s it all. Get to your blog and see your great stats being displayed. Feel free to share this tip or post your comments if you need any clarification or help which I would be glad to send in your way.

related reading

25 Responses so far