BlogoSquare

Essential problogging resources and downloads

Quick shooting stats of your Wordpress blog

March 30th, 2007 by Hans

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

Tags: 23 Comments

Leave A Comment

23 responses so far ↓

  • 1 Mauritius Blog Tracker Mar 29, 2007 at 8:02 pm

    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. See also this previous trick to show your wordpress blogging age! Share This © Hans for BlogoSquare, 2007. | Permalink | No comment | Add to del.icio.us | Search blogs linking this post with Technorati | Filed under under Blogging, how-to, wordpress. Read more here

  • 2 Yashvin Mar 30, 2007 at 5:41 pm

    thnks hans!
    i added it on my blog :P :cool: keep it up!

  • 3 Lorelle Mar 30, 2007 at 10:59 pm

    This is great, but you might want to put the first example code in the <code> tag and not a blockquote, and replace quotes and apostrophes with character entities to avoid the questions you are going to get to fix this because it won’t work when people copy and paste, as you have told them to do.

    Tips on how to do this are in this helpful article on putting code in WordPress posts.

    Thanks for doing this. It’s really great.

  • 4 Hans Mar 31, 2007 at 6:08 pm

    @ Yashvin

    nice to know it works… more check this out stuffs on the way :) stay tuned….

  • 5 Hans Mar 31, 2007 at 6:11 pm

    @ Lorelle

    thanks very much for your comment and the link…. I just put it that way since each time it displayed only part of the code when using the code tag.. seems like your article will be of great help indeed to me.

    Have you tried the above trick on wordpress.com?

  • 6 leo Mar 31, 2007 at 9:12 pm

    Hans, i thought you might want to know, me and kyu have tested this under very harsh conditione (You know, when we dissecated colourful wall.) The post count part does not exclude the [ages on your site.

  • 7 leo Mar 31, 2007 at 9:14 pm

    oops, [ages = pages :D

  • 8 Hans Apr 2, 2007 at 11:02 am

    @ leo:

    yeah perhaps wordpress consider them the same :) hey you could have asked me and I would have sent it your way instead of you breaking all this ice to find some gold lol :P

    thanks for trying it :) more in the directory to come :P for your great hackers at kyusphere… let’s see if you can figure out how I did the stuff for my category, that’s displaying and rotating 3 posts under each of its category :)

  • […] Quick shooting stats of your Wordpress blog […]

  • […] Quick shooting stats of your Wordpress blog […]

  • […] Quick shooting stats of your Wordpress blog […]

  • […] Quick shooting stats of your Wordpress blog […]

  • 13 David Airey Jun 20, 2007 at 7:58 pm

    Thanks for this, Hans.

    I’ve just added it to my site, and although there are actually only 194 posts, it says there are 200. Perhaps it counts pages too?

  • 14 Hans Jun 21, 2007 at 12:12 pm

    @ David

    yes the code counts pages too :sad: btw you could have a look at this one too allowing you to display your blogging age. Thanks for your visit and your comment.

  • […] Quick shooting stats of your Wordpress blog: displaying the number of posts, comments and categories one has on his Wordpress blog. […]

  • […] Quick shooting stats of your Wordpress blog: displaying the number of posts, comments and categories one has on his Wordpress blog. […]

  • 17 dada Sep 28, 2007 at 6:57 pm

    Nice Site!

  • 18 Wordpress Plugins | Lifehacker Oct 25, 2007 at 9:03 am

    […] Quick shooting stats of your Wordpress blog - 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. Related: […]

  • […] Quick shooting stats of your Wordpress blog […]

  • […] Quick shooting stats of your Wordpress blog […]

  • […] Blogosquare - Quick shooting stats of your WordPress blog […]

  • 22 Reliance Relocation Mar 7, 2008 at 7:30 pm

    Nice trick, thanks. I’m looking for a way to show how many visitors are there at any given time on the blog, you know a way?

  • […] Quick shooting stats of your Wordpress blog: displaying the number of posts, comments and categories one has on his Wordpress blog. […]