in PHP - 05 Jan, 2011, This Tutorial Has Been Viewed 28,090 Times.
Display total number of posts and comments in wordpress
This tutorial will show you how to display the total number of posts and comments in wordpress.All you have to do is edit your theme say your footer or header or sidebar as you wish and then add the following lines.
< ?php $numposts = $wpdb->get_var("S ELECT COUNT(*) FROM $wpdb->posts WHERE post_status = 'publish'"); if (0 < $numposts) $numposts = number_format($numposts); $numcomms = $wpdb->get_var("S ELECT COUNT(*) FROM $wpdb->comments WHERE comment_approved = '1'"); if (0 < $numcomms) $numcomms = number_format($numcomms); ?> < ?php echo 'There are '.$numposts . ' posts and ' . $numcomms . ' comments ' . $numcats . ' for this website'; ?>