How To Display Blog Statistics Like This Blog?
By Angsuman Chakraborty, Gaea News NetworkWednesday, November 16, 2005
This blog displays statistics on the right-sidebar (bottom) like - There are currently #### posts and #### comments in this weblog. The data is obviously dynamic.
Andre recently asked me how I do it. Here is a simple solution.
Embed the following code in your sidebar (or elsewhere) in location of your choice:
<?php $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); ?>
There are currently <?php echo $numposts ?> posts and <?php echo $numcomms ?> comments in this weblog. Enjoy!
You can also download the code(recommended).
Note: Make sure to copy paste exactly the code above. You may modify the message as indicated.
Note: This code has been adapted from WordPress Dashboard code.
December 10, 2005: 8:23 pm
Billy, Please download the code (as indicated in the post) instead of copying from the display. That should solve your issue. Let me know how it goes. |
![]() Billy |
![]() Billy |
December 10, 2005: 1:17 pm
When I add that code to my sidebar.php file (right above the closing of the last div tag) thru the Presentation Theme Editor screen, it just errors out with that code to that spot at the bottom of my blog screen. If I try to add it to the bottom of my sidebar.php file in Notepad, I don’t think it will work either, I’ll try emacs (anything else I should be aware of? |
Angsuman Chakraborty