I’m not in the habit of writing posts with answers that can be told in only two lines, but to this day I still see an awful lot of posts on Stack Overflow and the WordPress forums to warrant it. Getting the total post count in WordPress is really just about as simple as it gets.
How To Get Post Count In WordPress
$count_posts = wp_count_posts(); echo $count_posts->publish;
Variations For Getting Post Count In WordPress
You can alternate publish with any of the other post statuses, like draft to get the post counts of non-publishes posts.
Get Post Count Of Custom Post Types In WordPress
You can also get just the counts of custom post types or pages by specifying the post type in the wp_count_posts() first parameter.
$count_posts = wp_count_posts('the-custom-post-type'); echo $count_posts->publish;