Archive Index Page, How do I Make One?

written by Anthony Dinh

April 24, 2008 · Posted Under blogging | wordpress ·  

Your blog has been up and running for awhile and your posts are growing by the day, so now you would like to create an archives page to neatly list your previous posts.  Here’s a quick tutorial on how you can create an archive index like mine at  http://www.diariesofablogger.com/archives.  It nicely lists your previous posts by category, by month and the most recent N posts of your choice as shown below.

 

 archive.jpg

 

If you are using a free template that you found at one of the infinite Wordpress resource sites, then you may already have the template in your wp-content/themes/yourtheme folder, so check there first.  If it doesn’t already exist, here’s how you can create one.

1. make a copy of your index.php page and save it as archives.php
2. prepend the following code to the top of your newly created file

<?php
/*
Template Name: Archive Index Template
*/
?>

3. replace everything in between the existing “while loop” code with the following code (the loop starts with

<?php while(have_posts()) : the_post(); ?> and ends with <?php endwhile; ?>)
<?php if (have_posts()) : while (have_posts()) : the_post(); ?>
<h4>by Categories</h4>
<ul>
<?php list_cats(0, ”, ‘name’, ‘asc’, ”, 1, 0, 1, 1, 1, 1, 0,”,”,”,”,”) ?>
</ul>
<h4>by Month</h4>
<ul>
<?php wp_get_archives(’type=monthly’); ?>
</ul>
<?php endwhile; else: ?><?php endif; ?>

This will list all posts by category and by month.  Here’s a breakdown of the list_cats arguments that can be passed in the querystring:

<?php list_cats(optional, ‘all’, ’sort_column’,
’sort_order’, ‘file’, list, optiondates,
optioncount, hide_empty, use_desc_for_title,
children, child_of, ‘Categories’, recurse,
‘feed’, ‘feed_img’, ‘exclude’,
hierarchical); ?>

If you wish to list the N most recent posts, then replace the loop with

<?php while(have_posts()) : the_post(); ?>
<h2><?php the_title(); ?></h2>
<ul>
<?php
$myposts = get_posts(’numberposts=100&offset=0′);
foreach($myposts as $post) :
?>
<li><?php the_time(’m.d.y’) ?> | <a href=”<?php the_permalink(); ?>”><? php the_title(); ?></a></li>
<? php endforeach; ?>
</ul>
<?php endwhile; ?>

You can change the numberposts=100 and offset=0 variables to anything you’d like.

4. upload archives.php to wp-content/themes/yourtheme folder
5. create your archive index page from the admin panel->write->page

  • give your new page a suitable name like Archive Index
  • leave the page content area blank
  • in the Page Template section, select the Archive Index Template from the drop-down list, and save your changes
  • you should now see a link to your archive index in your pages list along the top of your page, or the pages widget in your sidebar.  alternatively, you can access your archives page at http://yourdomain.com/index.php?pagename=archive-index and verify that it’s working correctly

That’s it!  Now that wasn’t so hard was it?

 ** Find this post useful or entertaining? Then please consider subscribing to my full RSS feed or have new posts sent directly to your to email. **

Related Posts

  • JohnCow.com Sold for $50,000, That’s A Lot of Moooney!
  • I’m Not a Baby, Get Me Out of the Sandbox!
  • Affiliate Marketing Apprenticeship Program - Lesson 2/13
  • Too Lazy to Blog From Scratch? Purchase One from Sitepoint
  • Wordpress 2.5 Installation
  • Comments

    RSS feed | Trackback URI

    Comments »

    No comments yet.

    Name (required)
    E-mail (required - never shown publicly)
    URI
    Your Comment (smaller size | larger size)
    You may use <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong> in your comment.

    Trackback responses to this post