PureNews

PureNews is an amazingly sleek and powerful news theme with unlimited color variations.

View full feature list Check out the live demo Buy this theme today

Creating an Archives page in WordPress

Posted by on 13th Mar 2007 WordPress 5 comments

You will see that ive added an archives page to bloggingtips. It shows Archives by Month and Archives by Subject. WordPress is already setup to show old posts via the category archive on the sidebar etc but it’s good to have an archives page in addition to that.

In this post ill show you how to add an archives page to your wordpress powered blog

It’s incredibly easy to add an archives page in wordpress 2 onwards. All you need to do is create a blank page (eg write, write page via the wp admin panel) and then make sure you change the page template from default template to archives. Thats it. If you now look at the archives page you should see all posts listed by month and category. Enjoy!

Its not working….wordpress wont even let me change the template

If you cant see an option on the write page screen to change the template dont worry, it’s a common error and one which i got myself. The wordpress default theme has a few additional templates like archives and links (ill discuss links in my next article). However, if you are using your own theme or a theme which you downloaded from the net then theres a very good chance that you wont have these templates. Which is why you dont see the option to change the template – if wordpress only sees one template in the theme directory it removes the option for you to change the template as theres nothing you can change it to! So you need to create your own.

You should still have your default theme in word press (and if not shame on you!) so you can reference the archive template. To save you doing that though heres what the archives template looks like in kubrick (kubrick is the name of the default wordpress template)


<?php
/*
Template Name: Archives
*/
?><?php get_header(); ?><div id="content" class="widecolumn"><?php include (TEMPLATEPATH . '/searchform.php'); ?><h2>Archives by Month:</h2>
<ul>
<?php wp_get_archives('type=monthly'); ?>
</ul>

<h2>Archives by Subject:</h2>
<ul>
<?php wp_list_categories(); ?>
</ul>

</div>

<?php get_footer(); ?>

One thing you should note about the above is the code ‘Template Name: Archives’. This tells wordpress that it is a template file called Archives and it allows you to use this file as as a template.

Now what you need to do now is create a new file called archives.php. Note the s at the end – ie. wordpress already uses the file archive.php to search files etc. WordPress just happened to call their archives page the same name, except for one letter.

In this new file copy the code from your page.php template. At the top add the ‘Template Name: Archives’ code section just like the original archives.php file in your default theme directory. You also need to remove the post code etc and replace it with the code to generate the archives, namely this part :


<?php include (TEMPLATEPATH . '/searchform.php'); ?><h2>Archives by Month:</h2>
<ul>
<?php wp_get_archives('type=monthly'); ?>
</ul> <h2>Archives by Subject:</h2>
<ul>
<?php wp_list_categories(); ?>
</ul>

Now upload this to your theme directory. If you were using a theme called bloggingtips then you would upload your new archives.php file to wp-content/themes/bloggingtips/.
If you go back to your write page now you should now see the page template option which will allow you to change the template to our new archives page. Easy peasy!
* Note you will probably have to copy the searchform.php file to your theme directory too.

If you have any questions relating to this please let me know.
thanks,
kevin

Kevin Muldoon is a webmaster and blogger who lives in Central Scotland. His current project is WordPress Mods; a blog which focuses on WordPress Themes, Plugins, Tutorials, News and Modifications and useful resources such as 101 Places To Find Images For Your Blog Posts.

5 comments - Leave a reply
  • Posted by BOGDAN on 5th Sep 2008

    How can i add a list of posts for each month?

  • Posted by Kevin Muldoon on 6th Sep 2008

    Hi Bogdan,

    The code above will list your archives by month. Then the posts for that month will be displayed when you click on it.

    Do you mean you want every post listed?

    Kevin

  • Posted by Dea Smith on 2nd Dec 2010

    I am launching a website soon, and your details will probably be extremely exciting for me.. Thanks for all your assist and wishing you all of the success.

  • Posted by Edd on 6th Mar 2011

    I guess this was written a decade ago, right? Cos as far as am aware, all current wordpress themes already have archives section incorporated into them. thnx anyway mate.
    My recent post Anti-Aging Products for Anti Wrinkles And Anti Ageing Effects