Weblog Archive

Overriding posts displayed

Wed, 16 Jul 2008 at 22:58 • Chyetanya Kunte • Filed under Design

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?

[ Ads ]

Related posts

Following list is auto-generated, based on this post's context as possibly related. You may, however, occasionally find some in this list unrelated, but nevertheless, we sincerely hope that you'll enjoy them too.

Respond privately

Comments are closed, but you may respond privately to “Overriding posts displayed.” (Your response will not be published.)