« Technorati Tags and Movable Type | Main | Polls and Voting »

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:

Comments (23)

This is awesome, particularly for those of us who publish in the /year/month/entrytitle.ext format, because I always see a number of people hacking the address to see if /year/ exists. Now I just need to implement it!

NickB52286 Author Profile Page:

Excellent tutorial. But the archive template code above gave me a build error. I played with the code a little and this code works. If yours doesn't work, give this code a try. Replace the second part of the archive code above with this.

<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 lastn="1">
<a href="<$MTEntryPermalink$>" title="<MTEntryTitle remove_html="1">" >
<MTEntryTitle>
</a><br />
</MTEntries>
</MTCalendarIfEntries>
</MTCalendar>
</MTArchiveYearIfEntries>
</MTArchiveYearIfNotBlank>
</MTArchiveYear>
<br />

Hi Nick,
Thanks. It looks like you just moved the MTCalendar month="this" down below the MTArchiveDateHeader section. I don't understand all these tags well enough to know why this makes a difference and why the code I gave gives you a build error when it works for me. It took hours of experimentation just to get to work what I did get to work. But thank you so much for posting. Hopefully that will make a difference to anyone encountering problems.

Monolith aka Mikey Author Profile Page:

I'm not sure why, but I had to use Nick's modification too. It seems to work though. I guess i won't really know if it works until Jan 2006, as I just switched to MT this month.

Elise, your site has been such a wonderful blessing to me. Thank you so much! :-)

ollie Author Profile Page:

Thank you Elise for sharing the fruits of your "hours of experimentation". I too have spent a lot of time attempting to do this, unfortunately I finished up with nothing to share but frustration.

Thanks Nick for polishing it off. I too got a build error (fixed by moving MTArchiveDateHeader out of MTCalendar):

An error occurred:
Building date-based archive 'Monthly20050601000000' failed: Build error in template 'Yearly Archives': Error in tag: Error in tag: Error in tag: You used an MTArchiveDate tag without a date context set up.

Well, since Nick's modification seems to have been working for so many people, I made adjustments to the tutorial to reflect it. Thanks Nick!

Is there a 2.661 version of this code as well? I tried to find the right place to put the code, but it didn't seem to be there.

Any guidance would be most appreciated.

Is there a way to include the entry count in the yearly archive? I added back in the code but it's showing up a 0 count.

Good article, moreover the alternatives. However, there is not way to get MT-again. It would be great if the plugin (MT-again) could be available as the same as ArchiveYear.

Elise?

Your version of again.pl seems to have a little whitespace corruption in it. Some strings within the script meant to be on separate lines aren't ended with a newline whitespace character.

This causes perl on Unix systems, my system for example, to barf. You may want to check the file whitespace characters carefully and upload a clean copy to this site.

But thanks very much for putting a copy here! I was looking everywhere for a copy of this plug-in!

brian macauley:

again.pl does not load correctly in MT 3.2.

The plugin manager disables the plugin.

Any thoughts on why this happens?

Thanks,
Brian

Hi Brian,

Could be the white space issue noted in the comment before yours.

I've uploaded a zip file containing the again.pl that should work and changed the link in the tutorial above.

Mike Author Profile Page:

I'm having problem with getting MT 3.2 to respond to the tags created by the MTAgain and ArchiveYear plugins.

I installed them to my plugins directory as stated and my MT control panel recognizes that the plugins are installed and active.

The monthly archiving listing works perfectly as described above, but when I click on one of the year archives I get an error message screen with the following message:

Smarty error: [in mt:27 line 79]: syntax error: unrecognized tag 'MTArchiveYearPrevious' (Smarty_Compiler.class.php, line 580)

When I remove the offending code and refresh the page it goes to the next new plugin code and gives me the same message. It's like MT is ignoring the tag definitions in the plugins.

Has anyone else had this problem? Or does anyone know how to correct this problem? Thanks.

Carina Author Profile Page:

Hi!

After upgrading to the latest version MT3.32 the yearly archive will not work. It gives me errors similare to what others receieved before.

Also I copied your exact example but it will not show all the months with each months entry under montly label. It only lists all entries after first monthly headline.

Any idea on how or what to do about. See how the template works now http://carina.gokboet.nu/arkiv/2006/index_fel.php and how it used to work http://carina.gokboet.nu/arkiv/2006/index.php

Greatful for any help with this because I really liked the easy yearly archives.

Hi Carina,
When I check on the links from your site (both links) they appear to work. Did you fix something? Or perhaps the solution is as simple as emptying your browser cache?
I finally upgraded my main site (not LMT) to MT3.32 and was surprised and delighted that the Yearly archives on my Not Always On blog are still working. I would have expected something as complex and convoluted as that would still work.

Carina Author Profile Page:

Hi Elise,

I have the old version on the url ending with index.php The files that result now are the ones ending in index_fel.php wich show the whole year with all entries and no months. Before the upgrade from 3.3 to 3.32 they did do as they were supposed to. I have not made any new entries since because it gives errors trying to do it like before.

With the update 3.32 this is what I get if you view the index_fel.php

The code I am using today which also produces the long list of entries without the monthly part besides on the first month is what you have as an example.

What did do the pages correctly is this code but it will produce errors.


<MTArchiveYear skip="yes">
<MTArchiveYearIfNotBlank>
<MTArchiveYearIfEntries></br>
<MTCalendar sort_order="descend" month="this">
<MTArchiveDateHeader>
<p><h3><MTArchiveDate format="%B"></h3></p>

</MTArchiveDateHeader>

<MTCalendarIfEntries>
<MTEntries sort_order="ascend" lastn="1">
<a href="<$MTEntryPermalink$>" title="<MTEntryTitle remove_html="1">" >
<MTEntryTitle>
</a><br />
</MTEntries>
</MTCalendarIfEntries>
</MTCalendar>
</MTArchiveYearIfEntries>
</MTArchiveYearIfNotBlank>
</MTArchiveYear>

Carina Author Profile Page:

The code broke, strange. Maybe

Carina Author Profile Page:

Hi again Elise!

I found out what plugin makes this not do as I want and it to. When I removed the ArchiveDateHeader.pl it did output the yearly archives correctly. That means I have to hardcode my navbar year listing and that is strange. Maybe you know something about what I should do instead to get the automated years listing in the sidebar.

A questions, what plugin gives the live comment preview when I am writing here right now. Also what plugin are you using to have the email to a friend form below?

Thanks!

Carina

Hi Carina,

The code broke because you put real code into your comments which MT parsed like any other code. If you make a comment with code in it you need to pass it through a code converter first like this one: PHP Nuke Tools.

Regarding the Yearly Archives, it took many several days to get this technique to work on my site, and that was two years ago. I honestly have no recollection of how it works, I'm just surprised it still does work on my site.

Regarding Dynamic Comment Previewing, if you do a search on LMT, you'll find the tutorial, written by Jesse Gardner.

Regarding email to a friend, that feature used to be standard in the MT distribution. It no longer is, as I suspect that there are some security problems with it.

Glamoursmith:

This works well, however, I still need to list my entries by year only under the Category archive. Used to be able to do this with MTDateHeaders.pl, but once I upgraded to MT3.2 it stopped working. Any suggestions?

Stefan:

Just for your information, the code does not work completely if you do not have the MTArchiveDateHeader plugin. Just thought I'd point that out. I couldn't understand for ages why it didn't work.

After having some severe issues with the above code, I eventually resorted to a plugin called MTSomeDays. Since I filter some of my categories, this item uses the categories option in the tag:

<MTSomeDays group="month" select="year" categories="cat1:cat2">
  <p><h2><$MTSDWorkDate format="%B"$></h2></p>
  <MTSDIfEntries>
    <MTEntries sort_order="ascend">
      <MTEntryCategory>: <a href="<$MTEntryPermalink $>"><MTEntryTitle></a><br />
    </MTEntries>
  </MTSDIfEntries>
  <MTSDIfNoEntries>
    No entries.
  </MTSDIfNoEntries>
</MTSomeDays>

While you can continue to use MTArchiveYear for the navigation at the top, there is no need for it anymore for the entries. The end result is fairly the same as in the image above. You can tweak the <$MTSDWorkDate$> tag to suit your needs.

Now to try and see if I can recreate this to help do annual archives by category.

Post a comment

(If you haven't left a comment here before, your comment may need to be approved before will appear on the entry. Thanks for waiting.)