Learning Movable Type: Yearly Archives


mtbadge-small.gif

Movable Type is set up for doing date-based archives by day, week, and month, but not by year. There are a few plugins and methods out there that will help you create a yearly calendar of your archives, for example, Brad Choate's Year Archives in MT Perl script plugin will produce a calendar archive (example). Lummox JR's ArchiveYear plugin will produce a similar calendar (example).

I prefer a yearly archive to show a list of entries by month, as I've set up on one of my blogs (example). An archive page like this can be accomplished using the ArchiveYear plugin with some simple changes to the sample code given. Update August 1, 2005 The ArchiveYear plugin seems to not be in its regular location. Arvind has posted a copy of the plugin here. I assume that you would save the text file as archiveyear.pl and load it to the Plugins folder in your MT installation.

yearly-archive-page.gif

1. Download and install the ArchiveYear plugin. (Arvind has posted a copy of the plugin here.)

2. Create a new archive template

In your templates edit window, create a new archive template named "Yearly Archives". Copy and paste the code from your existing date-based template into this new template. If you are using the MT default template, remove all the code between the <div class="content"> tag and its closing div tag.

Add two blocks of code to replace the section you just removed. The first block will be the navigation row that toggles between the years. I have mine set up in a simple table:

<table border="0" cellpadding="0" cellspacing="2" width="200">
<tr>
<td width="80" align="center"><MTArchiveYearPrevious><a href="<$MTArchiveDate format="/path/to/your/archives/%Y/"$>">
&laquo; <$MTArchiveDate format="%Y"$></a></MTArchiveYearPrevious></td>

<td width="80" align="center"><b><$MTArchiveDate format="%Y"$></b></td>

<td width="80" align="center"><MTArchiveYearNext><a href="<$MTArchiveDate format="/path/to/your/archives/%Y/"$>"> <$MTArchiveDate format="%Y"$> &raquo;</a>
</MTArchiveYearNext></td>

</tr>
</table>
<br />

Be sure to replace "/path/to/your/archives/%Y/" with the path to your archives. For example, "/weblog/archives/%Y/"

The next bit of code lays out the months and links to the entries:

<h3><$MTArchiveDate format="%Y"$></h3>

<MTArchiveYear skip="yes">
<MTArchiveYearIfNotBlank>
<MTArchiveYearIfEntries>


<MTArchiveDateHeader>
<p><h2><MTArchiveDate format="%B, %Y"></h2></p>
</MTArchiveDateHeader>

<MTCalendar month="this">

<MTCalendarIfEntries>
<MTEntries>
<a href="<$MTEntryPermalink$>" title="<MTEntryTitle remove_html="1">" >
<MTEntryTitle></a><br /></MTEntries>
</MTCalendarIfEntries>

</MTCalendar>
</MTArchiveYearIfEntries>
</MTArchiveYearIfNotBlank>
</MTArchiveYear>
<br />

The ArchiveYear plugin documentation and the MT manual detail what the various tags do.

Save your template. But do not yet rebuild.

3. Finish creating the template.

For MT 3.2, in your settings window, select publishing. Click on the "Create New Archive Mapping" link. Add a new monthly archive, selecting the Yearly Archives template. Leave the existing monthly template as the preferred monthly template. Create a "custom" archive path for your Yearly template, for example: <$MTArchiveDate format="%Y/index.php"$> .

For MT 3.1 and earier versions, in your weblog config window, select archive. Use the Add New button to create a new archive template. Add another kind of monthly archive, selecting the Yearly Archives template. Leave the existing monthly template as the default. Choose a filename for your yearly archive. For example, <$MTArchiveDate format="%Y/index.html"$>. This will produce a yearly archive URL like so: http://www.yourwebsite.com/archives/2005/index.html. If your site is set up for php, use the index.php extension.

Save the settings and rebuild your monthly archives.

4. Set up links to your monthly and yearly archives from your sidebar

month-and-year-listing.gif

If you use monthly archiving, you probably have a section that links to your monthly archives in your sidebar. If you would like to set up this section so that it shows only links to months from the current year, and links to previous year archives, you will need a couple of additional plugins. MT-SetVarBlock is a tag available from both Brad Choate's Simple Template plugin and from Tim Appnel's mt-varz plugin. You will also need MT-Again. Update 12-11-05: I've posted the code to mt-again here as a zip file. Unpack the zip file and upload the again.pl to your web server to the plugins folder as ASCII text.

Arvind of Movalog has detailed the code needed for this in his Yearly Archives tutorial. I have used his code, but removed the entry count (MTArchiveYearCount) from it.

Place the code block on the sidebar section of your index template where you would like a list of months and years to appear.

<ul>
<MTSetVarBlock name="year"><$MTDate format="%Y"$></MTSetVarBlock>
<MTArchiveYear order="descend">
<MTArchiveYearIfEntries>
<li><a href="<$MTArchiveDate format="http://path/to/my/archives/%Y/%m/"$>" title="See all the entries for <$MTArchiveDate format="%B"$> <$MTGetVar name="year"$>">
<$MTArchiveDate format="%B"$>
<$MTGetVar name="year"$><br />
</a></li>
</MTArchiveYearIfEntries>
</MTArchiveYear>
<MTAgain>
<MTArchiveYearPrevious>
<li><a href="http://path/to/my/archives/<$MTArchiveDate format="%Y"$>/" title="See the Entries from my blogging year of <$MTArchiveDate format="%Y"$>">
Year Of <$MTArchiveDate format="%Y"$>
</a></li>
<$MTAgainHere$>
</MTArchiveYearPrevious>
</MTAgain></ul>

Make sure to again, replace the http://path/to/my/archives/ in the code to the actual path to your archives.

An Alternative

kalsey-dates.gif

If instead, you would like your monthly archive listing to be separated by years, without pointing to yearly archives, as described by Adam Kalsey, that can be accomplished with the MT-Archive-Dateheader plugin, maintained by Tim Appnel.

Many thanks to Arvind Satyanarayan of Movalog for his help figuring out the code in this tutorial. I was stumped, and once again, Arvind saved the day.

Links: Movalog's Yearly Archives tutorial


Posted by Elise Bauer on June 28, 2005 10:29 PM to Learning Movable Type http://www.learningmovabletype.com/