379
How to: Creating a Custom Archive Page Template in WordPress
13. December 2008

In WordPress there’s a feature to assign a custom template to any page within your blog. At my blog, for example, I’ve done this at the Archive page. You’ve got the ability to hard code anything into your page template so it’s extremely customizable.

In this small tutorial I’ll explain how you can create a custom archive page for your WordPress blog. The best way to start is to look for a file called: “page.php” in your theme directory (assuming you already have a WordPress theme, whether its downloaded or you’ve made it yourself). Once you’ve found that file, simply copy it and give the new file an identical name.

At the beginning of the file, paste the following piece of code:

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

You can obviously change the template name to whatever you like, as long as you remember what the page template was made for. As there are thousands of free and premium WordPress themes available on the Internet, you’ll understand that they’re not all the same. Try to find the “WordPress Loop” within the file, and delete the following code (or a code that looks like it):

<?php the_content(”); ?>

At the place where you found that code, you can now start coding your custom archives. You’ve got to put your code in here, because the original page content from your WordPress database was loaded at this place. To make sure you don’t break the theme and your custom page template looks the same as the rest of the pages on your blog, and everything is displayed properly (with the header, sidebar, footer, etc).

Now put the following code in here to show a list of months:

<h1>Monthly Archives</h1>
<ul><?php wp_get_archives(‘type=monthly&show_post_count=1′) ?></ul>

If you only want to show one category, place this code instead (change the number ’100′ to the ID of the category you’d like to show):

<ul><?php wp_get_archives(‘type=monthly&cat=100′); ?></ul>

Now you’ve added a monthly archives list, you may want to add a list showing your blog’s categories. To do this, easily add the code shown below:

<h1>Categories</h1>
<ul><?php wp_list_cats(‘sort_column=name&optioncount=1′) ?></ul>

After you’ve added the codes shown above to the template file, save it and upload it to your theme directory. Now create a new page via the WordPress admin and look for an option that says something like “templates”. You should see your template in the dropdown menu. Select your template and publish the page.

Digg Delicious Stumble Upon Reddit Twitter Subscribe by RSS Subscribe by Email

3 Comments on “How to: Creating a Custom Archive Page Template in WordPress”

Sunday, 4. January 2009 at 12:00 am

thank you for this tutorial

Sunday, 15. March 2009 at 9:36 pm

Nice post, i searching this tutorial for 1 hours, thanks guys

Thursday, 2. April 2009 at 2:27 pm

Hi Arjen,
Nice post . Thank you for the post.

Leave a comment