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>
<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 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.