How to define how many post to display per page

By default, the WordPress loops displays 10 posts per page. But in case you’d like to display more or less posts, here’s how to achieve it.

The solution to that common issue is pretty simple: You have to use the query_posts() function, which gives you a total control over the WordPress loop.

To specify how many posts you want to be displayed per page, we'll use the showposts parameter.

Here's an exemple:

<?php
$page_num = $paged;
if ($pagenum='') $pagenum =1;
query_posts('showposts=7&paged='.$page_num); ?>
               	<?php if (have_posts()) : ?>
		<?php while (have_posts()) : the_post(); ?>
                // WordPress loop
                endwhile;endif; ?>

This exemple loop will displays 7 posts per page. This is the code I use on WpRecipes.
Did you noticied the paged='.$page_num parameter? This allows use to display our content by pages and use a paginator.

Leave a Comment

* Name, Email, Comment are Required