Overriding posts displayed
I typically display 9 posts per page—by design, on this WordPress powered site. As an unintended consequence, my monthly archives page, and my search results page would show a paged list of 9 posts. How annoying.
The call query_posts fixes this problem. By adding this following line before the loop, I am able to list my entire monthly archive displayed in a page (thus effectively overriding my 9 posts limit that I set in Dashboard → Settings → Reading):
<?php query_posts($query_string.'&posts_per_page=-1'); ?>
The value -1 set for &posts_per_page lists everything in one page. For search results, however, I’d prefer to restrict the list to 50 per page. Easy:
<?php query_posts($query_string.'&posts_per_page=50'); ?>
The result: a typical monthly archive, and a typical search results list.
For fun, try removing $query_string. from the first line of code above, and you’ll notice how it produces an entire list of posts ever written. Archives, Sitemaps anyone?
