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

StevenOne responseWordPress

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);
?>

Learn how I made $33,543 online in the past 12 months.

Simply input your best email below to get started.

<?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.

Learn how I made $33,543 online in the past 12 months.

Simply input your best email below to get started.

One Comment

  1. Wallpapers

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

Learn how I made $33,543 online in the past 12 months.

Simply input your best email below to get started.

No thanks, I have enough money