Customizing WordPress archives page

So I finally got around to customizing my archive.php page. I wanted links to single posts rather than list full posts for pages and pages. Editing the loop was easy enough — I just pared down the loop code to make a list of permalinks. The tough part was getting every post to show up in that list.

Introducing query_posts()

If you're unfamiliar with it, the function called query_posts() will alter what shows up in the WordPress loop. You can choose categories, show a certain number of posts, exclude posts, etc. I'm used to modifying it for my blog's home page, but I needed to know how to use it for archive.php.

My first instinct was to have just 1000 posts show up, but then the WordPress Codex came through for me.

You can show every post if you set showposts=-1.

Now if I just used

<?php query_posts(showposts=-1); ?>

I would get every post I've ever made, in every category, month — everything in my blog.

Show every post in the chosen category

But I want to show every post in the category my user clicked:

<?php query_posts($query_string . '&showposts=-1'); ?>

The big Q is: what is $query_string? Archive.php gets fed a request depending on what link you clicked on, e.g. a date (February 2009), category, or author. WordPress was generous enough to deliver that request in $query_string. That way you don't have to try and divine what your user clicked on.

One Response to "Customizing WordPress archives page":

  1. Nathan wrote:

    November 23, 2009 at 11:41 am | Link to this Comment

    You lifesaver! Thank you, I just realised that my archive page pulling in different categories using query_posts was stuck on all posts, I could have been pulling my hair out for hours if it wasn’t for your post.

    Thanks,

    Nathan


Leave a Comment