Wednesday, May 20, 2009

Wordpress: Archives page and archives link

Creating an archives page is easy enough but how do you do that? It has been confusing at first but after several hours again of searching the web I found a solution to my issue.

First you really do need to create an archives.php template and here is how it looked:

<?php

/**

* Theme name here

*/

/*

Template Name: Archives

*/

get_header() ?>

<div id="content"><div class="entry">

<h2>Archives by Month:</h2>



<?php wp_get_archives('type=monthly'); ?>


<h2>Archives by Subject:</h2>



<?php wp_list_categories(); ?>



</div>




<?php get_sidebar(); get_footer(); ?>

Please do take note to name the template in the comments above, I haven't had any idea yet if I should but it is a good practice to do so. So above I named it 'Archives' the same as the file name, make sure it is uploaded in the theme's folder. In order for this to show up you need to create a static page. If you are using wordpress 2.7.1 go to Page>Add New, just give it a title of Archives and to the right there is or there should be a dropdown of the template to use, choose the Archives template, don't put anything in the content text area just make sure you have a title, then hit save.

Now that you have this how do you create a link, pretty simple, here is the code:
<a href="<?php echo bloginfo('url').'/'.'?pagename=archives'; ?>">Archives</a>
That is it, happy coding. ;)

No comments:

Post a Comment