Taming Archive Lists

One slight irritation with Movable Type is that when you’ve been running a blog for some time, the list of monthly archives that (by default) appears on the index page can get a bit long and take up too much space.

So I’ve written a bit of Javascript that addresses that problem. I’ll package it up nicely and release it later, but in case anyone is interested, the code is here.

What you need to do is to put that code in the <head> section of any template where you want the abbreviated list to appear. You then need to make two other changes to the template:

  1. You need to run the show_yr function as the pages loads. You can do this by changing the <body> tag to look like this:

    <body onload="show_yr(max_year, 'years')">
  2. You then need to define a <div> element where you want the list to appear. It needs to have an id which matches the second argument to the show_yr call (so in the example above, that’s “years”. It will look something like this:

    <div id="years">
    </div>

And that’s it. When you rebuild the site, you’ll get an abbreviated list of the monthly archives. There’s an example on this page. Clicking on a year will open out the list to display the months for that year.

Any comments and suggestions are welcome – particularly on my Javascript as I know it’s not great.

It even seems to work in IE6 – which is a bonus as I wasn’t aiming at that at all :)

3 comments

  1. Because it’s inserting literal text in the serialized form of the document. Conceptually it’s on par with using regexes to grope around in XML documents. It won’t work with XHTML either for this reason. Use the DOM interface instead: call createElement on the document to create a node and appendChild or such to establish relationships.This chapter from O’Reilly’s JavaScript: The Definitive Guide should contain more than enough pointers to get you going.

Leave a comment

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.