Dukeo » WordPress » Total Post Number: How To Display It On Your WordPress Blog

Total Post Number: How To Display It On Your WordPress Blog

Steven One response WordPress

For many reasons, you may want to display the total number of posts on your WordPress blog. However, WordPress doesn’t have any build-in function to do that.

To display the total number of posts on your WordPress blog, paste the 2 following pieces of code on your pages:

<?php
$numposts = $wpdb->get_var("SELECT COUNT(*) FROM $wpdb->posts WHERE post_status = 'publish'");
if (0 < $numposts) $numposts = number_format($numposts);
?>

<?php echo $numposts.' posts has been published on this blog'; ?>

The first part of the code uses a loop to compute the total number of posts on your WordPress blog. The second part of the code is used to display the result.

If you enjoyed this article,
Get email updates

Join for Free »

One Comment

  1. Wallpapers

    Thanks i will try this code now.
    Do i need to add some code to the functions.php too?