zw

Creating an archives page with WordPress

I don't really see the usefulness in viewing blog archives by month or year. I'm not particulary interested in what someone wrote in November 2008. If I'm looking at your blog, I care what you write about, not when1. I'm not sure why so many blogging systems make a monthly display the default for archives, when a list of the posts is much more usable.

Screenshot Thumbnail Fortunately, this is really easy to accomplish with WordPress. Take a look at my archives page for an example.. Since writing this I've moved my blog from Wordpress to Tumblr and that page is no longer live. Here's a screenshot of what this page looked like- This list all the posts I've written from newest to oldest. Someone can instantly took a look and see if there is something they want to read.


archives_template To create an archives page, create a new "Page", and set the template to "Archives" (see image). This should appear automatically in the dropdown, if it doesn't, create an archives.php file in your current theme, and make sure there is a header like this:

<?php
/*
Template Name: Archives
*/
?>

Once you save that page, if you're using the default WordPress archives.php, it will list "Archives by Month" and "Archives by Subject". Edit the archives.php file, remove those sections, and add the following code:

<? $posts = get_posts('numberposts=-1');
  foreach ($posts as $post) :
     setup_postdata($post);
  ?>
    <div class="post" id="post-<?php the_ID(); ?>">
      <h2><a href="<?php the_permalink() ?>" rel="bookmark" title="Permalink to <?php the_title_attribute(); ?>"><?php the_title(); ?></a></h2>
      <p class="date_comments"><?php the_time('M j, Y'); ?> - <?php comments_number('0 Comments', '1 Comment', '% Comments', 'comments_count'); ?></p>
    </div>
<? endforeach; ?>

Of course, you'll want to adjust this for your own site as this formatting is specific to my site. Now you have a nice, useful page with all your posts clearly displayed. I'm a proponent of this view even if you have a couple hundred posts, I'd still like to be able to see everything in one shot.

1 Of course I actually do care when it was written, especially if it's technology related. If it was written in 2001, it may be obsolete, but I'm not going to find content based on date.