Is there a way to know the total number of posts before the loop starts? I’m thinking in use two loops. The first will do the counting, while the second one will handle the content. However, I don’t think this approach is ‘elegant’. Any other solutions?
2 s
functions.php:
function wpse8170_get_posts_count() {
global $wp_query;
return $wp_query->post_count;
}
index.php:
if (have_posts()) :
echo '<h1>' . wpse8170_get_posts_count() . ' Posts Found</h1>';
while ( have_posts() ) :
the_post();
//...
endwhile;
endif;