Add Archive Page to WordPress the Easy Way

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?

Advertisements

5 thoughts on “Add Archive Page to WordPress the Easy Way

  1. Add Archive Page to WordPress the Easy Way – Montana Programmer…

    A tutorial on how to add an archive page to your wordpress blog. This example does not use a wordpress plugin and is a simple method for adding an archive page to wordpress….

    Like

  2. I’m a relative newbie (well not relative, I am a newbie) to wordpress coding and all this jazz…so I had an archives page for a different theme..switched to my current theme and the theme creators disabled the archives page so that you have to have pro to have it. So, I went in with your tutorial here and gave myself back my archives page (I’ll show them!)..it worked..then they pushed an update through and they erased my archive template again!
    Anyways, now I just have to figure out where they hid the font color as the style.css page is empty of anything in it..like what they did with the archive page.

    Like

Comments are closed.