WordPress: Create custom archive page

This article shows how to create a custom archive page for your wordpress blog. In the following archive page, I have displayed yearly archive, monthly archive, category wise archive and all post archive. So, the newly created archive page will be a kind of all-in-one archive page.

Here is the step-by-step guide:

1) Create a file archives.php

2) Write the following code in it.


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

<?php get_header(); ?>

    <div id="content">

    <?php if (have_posts()) : while (have_posts()) : the_post(); ?>

    <div class="post" id="post_<?php the_ID(); ?>">

    <h2 class="title"><?php the_title(); ?></h2>

        <div class="entry clearfloat">
            <h3>Yearly Archive</h3>
            <ul><?php wp_get_archives('type=yearly&show_post_count=1'); ?></ul>
            <h3>Monthly Archive</h3>
            <ul><?php wp_get_archives('type=monthly&show_post_count=1'); ?></ul>
            <h3>Category Archive</h3>
            <ul><?php wp_list_cats('sort_column=name&optioncount=1') ?></ul>
            <h3>Posts Archive</h3>
            <ul><?php wp_get_archives('type=postbypost') ?></ul>
        </div>

    <?php edit_post_link('Edit this entry.', '', '</p>'); ?>

    </div>

    <?php endwhile; endif; ?>

    </div>

<?php get_sidebar(); ?>

3) Upload it (archives.php) in your current wordpress theme directory.

4) From WordPress admin panel, create a page name Archives.

5) For this page, set Template to Archives. i.e. Attributes -> Templates = Archives (In WP 2.8, you should find ‘Attributes’ under ‘Update Page’ button).

6) Publish the page and you are done.

Thanks.