Twitter Updates

    follow me on Twitter

    WordPress Wonkery: List of Posts By Tag

    I recently went looking for a way to create a page in WordPress with a list of all the posts by a specific tag. (For example, every post tagged with “FO” or “Sims Sunday“.) I wasn’t able to find the answer online. I did finally find it in the WordPress documentation, albeit worded in a very roundabout way.

    Here’s how to do this:

    1. Use the query_posts tag, with ‘tag=whatever’ as a variable:

    <?php query_posts(‘tag=sims-sunday’.’&posts_per_page=-1′); ?>

    To get the specific syntax for the tag, find a post with that tag, and click on the tag. You will go to a URL such as:

    Snip off everything after the question mark and drop it in as your first query_posts argument.

    “posts_per_page=-1” means “list all of the posts with this tag on one big page.” If you want to list 50 posts per page (with a link for “older” so that people can page through) the syntax would be “posts_per_page=50”. And so forth.

    2. Put this before (i.e. outside) The Loop.

    To create a page which just has the post titles (as opposed to a page with the actual content of each post, one after the other) strip out all of the content-related tags except for the_permalink and the_title.

    3. Save this and upload it as a template file to your theme’s directory.

    For an example of how the template file will look, you can check out my template file for the Sims Sunday page. (Feel free to crib from this file as freely as you like.) You may want to compare it with my Main Index template.

    4. Create a new Page (not a Post – a Page). Set the new template file as the page’s Template.

    Note that if you want to say anything on this page (beyond listing the posts), you will need to write it in the template file itself. (Consult the Sims Sunday template file above to see where I put my preamble.)

    2 comments to WordPress Wonkery: List of Posts By Tag

    Leave a Reply




    You can use these HTML tags

    <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong>