Codeable info

How To Create An Archives Page

Posted on by in WordPress Tutorials

The archives page is a page template which allows you to display older posts by category and date. Many themes do not have an archives page template so visitors can only search using the category and monthly archive links on the sidebar (which is powered by the archive.php file, not archives.php). Due to this, it is sometimes necessary to create your own archives page.

Some bloggers don’t bother creating an archives page but I think it’s always good to add one as it gives visitors more ways of finding older content.

Creating the Archives Template

The first thing you need to do is open up your text editor and save a blank file as archives.php. You can edit this file directly on your computer and then upload it to your theme folder. If you prefer to edit files via your WordPress panel (which I do) then you need to upload your blank archives.php file to your theme folder online and make sure you change the file permissions to 666 (Owner, Group and Public read and write).

The first piece of code you need to add to your archives.php file is:

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

Make sure the above code is at the top of your archives.php template. Then you need to add the code from your Page Shell underneath that (the Page Shell is the code from your page.php template with the WordPress Loop removed).

Now we just need to call up the appropriate functions within our templates.

  • wp_get_archives() – By default this function displays older posts per month though you can change it to daily, weekly or yearly.
  • wp_list_categories() – By default all categories are ordered in alphabetical order though there are over a dozen arguments at your disposal so you can change the way posts are listed in a number of ways.
  • wp_list_authors() – A useful function to add to your archives.php if your blog has multiple authors.
  • wp_tag_cloud() – Another useful function which is worth adding to your archives page if you tag your blog posts a lot.
  • get_search_form() – It isn’t always necessary to include a search form in your archives page, particularly if your theme has a search box in a prominent position (which it should be). However, it may be worth including at the top or bottom of your archives page. For example, you can advise the visitor that they can search your blog directory using the search box if they can’t find what they’re looking for in the archives listings.

Here is an example of an archives page. Remember, your archives page will look a little different since most themes are structured differently.

<?php
 
/*
 
Template Name: Archives
 
*/
 
?>
 
 
<?php get_header(); ?>
 
 
<div id="content" class="narrowcolumn">
 
 
<?php get_search_form(); ?>
 
 
<h2>Archives by Month:</h2>
 
<ul>
 
<?php wp_get_archives('type=monthly'); ?>
 
</ul>
 
 
<h2>Archives by Subject:</h2>
 
<ul>
 
<?php wp_list_categories(); ?>
 
</ul>
 
 
<h2>Archives by Author:</h2>
 
<ul>
 
<?php wp_list_authors(); ?>
 
</ul>
 
 
<h2>Tag Cloud:</h2>
 
<ul>
 
<?php wp_tag_cloud(); ?>
 
</ul>
 
</div>
 
 
<?php get_footer(); ?>

Creating an Archives page

The last thing you need to do is create the Archives page itself. To do this, all you need to do is create a new page through your WordPress admin area and call it Archives, though you can call it anything you want.

Any text which you type at the top of your archives page will appear before the archive information which is being generated from our Archives Template. This is useful if you want to write a small introduction or description before the archive results.

Then you need to make sure WordPress uses our new Archives Template for this page.

Make sure you change the template to the Archives Template

Now all you need to do is click publish and check out your new archives page :)

If you are unsure about any stage of this process, please let me know in the comment area.

Thanks,
Kevin

)
Codeable info

Comments (1)

Comment by The difference between Archive.php and Archives.php - WP Mods says:

[…] writing a tutorial about creating an archives page last week I was reminded about the confusion which arises between the Archive.php and Archives.php […]

Codeable info