Using WordPress core function
wp_count_posts, you can easily display total number of posts. Here is a simple example on how to use this function:
<?php $count_posts = wp_count_posts(); $published_posts = $count_posts->publish; echo 'We published ' . $published_posts . ' posts until now, and it's still growing..'; ?>
This displays a text output like this;
We published 1908 posts until now, and it's still growing..
wp_count_posts you also get other counts like drafts, requested posts etc. Here is a sample output showing what
wp_count_posts returns as an Object:
stdClass Object ( [publish] => 1908 [future] => 0 [draft] => 9 [pending] => 0 [private] => 1 [trash] => 0 [auto-draft] => 19 [inherit] => 0 [request-pending] => 0 [request-confirmed] => 0 [request-failed] => 0 [request-completed] => 0 )
In your theme, you can use any of those properties to display number of posts.