Making Yearly Archives in MT using MTWikiVar
Posted by aogSunday, 09 November 2003 at 21:38 TrackBack Ping URL

This is detailed “how-to” article on how to build a yearly archive as seen on this weblog.

1) Install MTWikiVar (see the instructions).

2) Create another plugin file to setup up WikiVar function variables and put it in the same director as the other plugins (“mt/plugins”). It doesn’t matter what the name is as long as it’s not the same as any other plugin. I call mine “”. It looks like this:

package MT::WikiUtil;
use strict;
use vars qw($VERSION);
$VERSION = "1.0.0";

# Return our version
sub Version { return $VERSION; }
# ----------------------------------------------------------------------------
sub MakeYearArchive {
    require Transfinitum::YearArchive;


What this file does is create a subroutine that can be used in a MTWikiVarDefun. The definition is minimal and just fowards the call to the real code to reduce load times when this function is not used.

3) Install the YearArchive subroutine package. Create a directory called “Transfinitum” under the “extlib” directory. Put the file there.

4) Create a new index template for the archives for a particular year. Put in whatever header / banner stuff is appropriate. Note that this the code YearArchive generates the year calendar only.

The actual work is done by putting the following code in the template.


This will make the year archive for 2002. You can see this in action.

These don’t have to be together. I put the Defun up in the HEAD element.

5) Rebuild the index template for your yearly archives.

The yearly archive has the following features:

  • Every date is linked to the first post for that date.
  • The month title is linked to the monthly archive if it exists.
  • The hover text on a day is all of the titles of the posts for that day.

If you want to tweak the formatting, the best option is to wrap the MTWikiEval elements inside a DIV and use the “style” attribute on the DIV to adjust things such as font size. Alternatively, use the “class” attribute on the DIV and define the styling in your style sheet.

P.S. Here is the complete text of the template used to generate the yearly archive example.

  html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"

<html xmlns="">
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />

<$MTWikiVarDefun name="MakeYearArchive" value="MT::WikiUtil::MakeYearArchive" $>
<link rel="stylesheet" href="<$MTBlogURL$>styles-site.css" type="text/css" />

<body><MTInclude module="Banner">
<div class="content">
<div style="text-align:center;text-decoration:overline;font-size:200%;font-family:garamond;">
<u><b>The Year In Review — 2002</b></u></div>
<div class="calendar-year-table">
Comments — Formatting by Textile
dvd Thursday, 13 November 2003 at 06:12

are there any advantages to using this method over the dedicated plugin archiveyear, which is what i currently use?

aog Thursday, 13 November 2003 at 08:58

The biggest advantage is that there are a lot fewer tags to mess with. As you can see from the template listed above, the grungy bits of actually laying out the months is done by code, not in the template. Can you put the YearArchive based template code in a template module and MTInclude it in the various indices?

This version also does the post titles in the hover text, but that’s just MT Tag trickery would could be done with YearArchive. The links to monthly archives is probably not doable, as I couldn’t figure out any MT Tags to do that. I had to use the MT PERL API.

If you already have YearArchive working, it’s unlikely to be worth the hassle to switch. I’d switch if you decide to install “WikiVar”:777 for some other reason, because then you will have already done most of the work.

To a large extent, this is a “WikiVar”:777 demonstration project. You could do the same thing in a single MT plugin tag that took the year as an attribute. You’d just need a bit of a different wrapper on the real code in

dvd Thursday, 13 November 2003 at 11:07

i like the power the archiveyear plugin gives me with the display of the result though — it appears the table layout of each month is hard-coded into, whereas the dedicated plugin has all the flexibility of using mt’s calendar tags within the template. if you have already got the calendar in tune with the rest of your site, it’s a matter of wrapping a few container tags around it to get the year review.

ijliao Friday, 21 November 2003 at 11:23
I’ve gotten a problem that I got one more tag after YearArchive finished month 11 thus, my calendar looks like ((1 2 3)(4 5 6)(7 8 9)(10 11)(12)), it’s strange Maybe there’s something wrong with this line $text .= ‘’ if (($_ % 3) == 0); # last in row but I’m not very sure …
Annoying Old Guy Friday, 21 November 2003 at 13:03

I’ll take a look. It may be that I don’t have the latest version up for download, because I don’t see that effect on the weblogs I have it installed on (such as this one).

The final line is correct - it should emit the closing TR element for months that are 0 mod 3, e.g. month 12.

I tweaked the script a bit to take care of a potential bug (even though I don’t see it in any of my 3 different PERL environments). Download a new copy and try it. Otherwise, email me a link to your website / archive so I can take a look at the output.

End of Discussion