Adding an archive page to your WordPress blog is simple, but there are a few things that are not self explanatory or obvious with this process. This tutorial goes through how to do this with the latest version of WordPress (2.x). Also included is some sample code that I use for this website that you are free to use.
Step #1: Create the WordPress Theme Archive File
Your theme will need a page to handle the archives. The theme I used had a file called “archives.php” that I used for this. If your theme does not have a file like this, you will need to create one.
Below is my archives.php template file.
<?php /* Template Name: Archive */ ?> <?php get_header(); ?> <div id="content"> <div id="content-left" style="padding-top: 20px;"> <div class="post"> <h1><?php the_title(); ?></h1> <ul> <?php wp_get_archives('type=monthly'); ?> </ul> </div> </div><!-- end content-left --> <?php get_sidebar(); ?> <div class="clear"></div> </div><!-- end content --> <?php get_footer(); ?>
Lines #1-#5 are very important. Even if your theme has an archives.php file, you will want to make sure that those lines are the first five lines of the file. I had to add these to my template file.
The php code “” grabs the posts by month, which works out well for this blog. You can change this to type=yearly or something different (the official function reference can be found here).
Step #2: Create a new WordPress Page
In your admin panel, go to Pages: Add New. If you completed step one properly, you should see an Attributes section in the right option area, where there should be a selection tool for that page to use a template. The template file you created above should be in that list (mine was called Archive). Make sure to select that option.
You will want to give the page a title and specify the permalink for the page. Once you click publish, the archive page should come up for that permalink.
If you have a WordPress blog, how do you handle archives?