Display the total number of posts on your WordPress blog
It would 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.
We're using the $wpdb object to make a custom query to WordPress database. Paste these code into functions.php.
Right now, the $numposts variable contains the total number of posts. You now just have to display it where you want:
We're using the $wpdb object to make a custom query to WordPress database. Paste these code into functions.php.
$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'; ?>