Thursday, January 1, 2009

How to create WordPress Archives page

To create an archives page for WordPress, you can use the Page Template feature. Here are the steps:

  1. Create an empty file—using your favourite text editor— in your theme folder, and name it archives.php, or whatever you like.

  2. Append these codes inside archives.php.
    /* Template Name: Archives */
    <?php get_header(); ?>
    <div id="archives">

    <h2>Archives by Month:</h2>
    <ul> <?php wp_get_archives('type=monthly'); ?> </ul>

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


    <?php get_footer(); ?>

  3. Create a new page in WordPress, and name it Archives.
    Create new page

  4. Change the Template Attributes for Archives page, which is usually located at the right hand side of the Edit Page page,  to Archives (The name will depends on the template name).
    Change the page Template Attribute.

  5. Click on the Update Page button to save.

Now, you already have an archives page by month and by subject/category. By the way, you could also have the archives page to display some or all posts title, as discussed in this article.

1 comment :

  1. [...] this code, you can list all titles of WordPress posts in one page. An example of usage is in an Archives page. 1 2 3 4 5 6 7 8 9 <ul> <?php global $post; $myposts = [...]