Wouldn’t it be nice to be able to display the total number of posts published on your WordPress blog? WordPress don’t have a function to do that by default, but happilly this hack is here to help.
Here’s the code: We’re using the $wpdb object to make a custom query to WordPress database:
$numposts = $wpdb->get_var("SELECT COUNT(*) FROM $wpdb->posts WHERE post_status = 'publish'"); if (0 < $numposts) $numposts = number_format($numposts);
Right now, the $numposts variable contains the total number of posts. You now just have to display it where you want:
<?php echo $numposts.' has been published since January 12, 2008'; ?>
Thanks to Perishable Press for this great hack!