Year Archives in MT

It's a shame MT doesn't provide year-based archives because some of us have enough entries for them even if Movable Type hasn't been out that long! Here's what my 2001 blogging year looks like. Well, you can create them manually-- and since you only have to do it once a year, it isn't too bad. Click the 'more' link for details...

All you have to do to build a year archive is create an index template for each year. In my case, I created one for 2001 called "2001 Index" and gave it a filename of "past/2001.php". For the template itself, you use a series of "MTCalendar" tags specifying the month attribute for the year and month you want to produce. That means you need 12 MTCalendar tags (and their associated baggage) in all.

Now, while you can write all that MT code manually, I decided to use my PerlScript plugin to do the work. I created a template module I named "year_view.pl" and this is what it contains:

# the goal of this script is to produce a calendar
# view of the current year using MT Calendar tags.

# call this script with a 'year' attribute.
# it will use the current year if no year is given.
my $year = $args{year} || ((gmtime(time))[5]+1900);

# we need the blog object to call format_ts so
# month names match the locale of the blog.
my $blog = MT::Blog->load(<MTBlogID>);

# header
print <<EOT;
<table width="90%" align="center">
<tr><td colspan="3">$year</td></tr>
EOT

# each month is produced by this loop
for ('01'..'12') {
  # start a new row for every 3rd month
  if ((($_-1) % 3) == 0) {
    print qq{<tr valign="top">};
  }
  # print a single month within a table cell
  print "<td>".month("$year$_",$blog)."</td>";
  # row closure
  if (($_ % 3) == 0) {
    print qq{</tr>};
  }
}
print <<EOT;
</table>
EOT

sub month {
  my ($month, $blog) = @_;
  my $date = MT::Util::format_ts("%B %Y",
    $month.'01010101',$blog);
  
  # you can customize the format of your calendar by
  # changing the HTML below. Note that the 'MT' tags
  # have been altered to 'ZZ' instead so they aren't
  # evaluated BEFORE the Perl code is executed:
  my $cal = <<EOT;
<table border="0" cellspacing="4" cellpadding="0">
<tr>
<th colspan="7"><span
  class="calendarhead">$date</span></th>
</tr>
<tr>
<th><span class="calendar">Sun</span></th>
<th><span class="calendar">Mon</span></th>
<th><span class="calendar">Tue</span></th>
<th><span class="calendar">Wed</span></th>
<th><span class="calendar">Thu</span></th>
<th><span class="calendar">Fri</span></th>
<th><span class="calendar">Sat</span></th>
</tr>

<ZZCalendar month="$month">
<ZZCalendarWeekHeader><tr></ZZCalendarWeekHeader>
<td align="center"><span class="calendar">
<ZZCalendarIfEntries>
<ZZEntries lastn="1"><a href="<ZZEntryLink
  archive_type="Daily">"><ZZCalendarDay></a>
</ZZEntries></ZZCalendarIfEntries>
<ZZCalendarIfNoEntries><ZZCalendarDay>
</ZZCalendarIfNoEntries>
<ZZCalendarIfBlank> </ZZCalendarIfBlank></span></td>
<ZZCalendarWeekFooter></tr></ZZCalendarWeekFooter>
</ZZCalendar>
</table>
EOT
  # this is just a little mechanism to keep the 'MT'
  # tags from being evaluated until we actually print
  # them out from the PerlScript code...
  $cal =~ s/ZZ/MT/g;
  $cal;
}

Now, to call this PerlScript code from your template, do something like this:

<MTPerlScript year="2001">
  <MTInclude module="year_view.pl">
</MTPerlScript>

That's IT! Now, just create an index template for each year you want to archive, and change the 'year' attribute shown above to match the year of the template you're producing. I would also recommend turning off the 'Rebuild this template automatically when rebuilding index templates' option for prior years but enabling it for the current year.

TrackBack

TrackBack URL for this entry:
http://bradchoate.com/mt/feedback/tb/241

Listed below are links to weblogs that reference Year Archives in MT:

» yearly calendar archives from Girlie's Tips and Tricks
While searching through old bookmarks, I came across Brad Choate's Year Archives in MT entry, which utilizes his PerlScript plugin [Read More]

» More Plugin Fun from Digital Daydreaming
I'm discovering that these Movable Type plugins can be addictive. I'm now using BlogTimes from Nilesh Chaudhari and MTPerlScript from [Read More]

» More Plugin Fun from Digital Daydreaming
I'm discovering that these Movable Type plugins can be addictive. I'm now using BlogTimes from Nilesh Chaudhari and MTPerlScript from [Read More]

» More Plugin Fun from Digital Daydreaming
I'm discovering that these Movable Type plugins can be addictive. I'm now using BlogTimes from Nilesh Chaudhari and MTPerlScript from [Read More]

» More Plugin Fun from Digital Daydreaming
I'm discovering that these Movable Type plugins can be addictive. I'm now using BlogTimes from Nilesh Chaudhari and MTPerlScript from [Read More]

» Various tricks with archive calendars from Sillybean
These tricks apply to the tiny calendars that appear on your home page, not the full-screen monthly archives from my [Read More]

» Various tricks with archive calendars from Sillybean
These tricks apply to the tiny calendars that appear on your home page, not the full-screen monthly archives from my [Read More]

» Yearly index from Boon Kwee's Blog
Brad Choate: Year Archives in MT wow! [Read More]

» Perlscript and Yearly Calendars from Simplicity and Chaos
I've just installed Brad Choate's Perlscript plugin. It enables you to use the Perl scripting language within your templates. I don't know Perl, but Brad's come up with some great plugins and tips that use it, so I've installed it. [Read More]

» Perlscript and Yearly Calendars from Simplicity and Chaos
I've just installed Brad Choate's Perlscript plugin. It enables you to use the Perl scripting language within your templates. I don't know Perl, but Brad's come up with some great plugins and tips that use it, so I've installed it. [Read More]

» Perlscript and Yearly Calendars from Simplicity and Chaos
I've just installed Brad Choate's Perlscript plugin. It enables you to use the Perl scripting language within your templates. I don't know Perl, but Brad's come up with some great plugins and tips that use it, so I've installed it. [Read More]

» Perlscript and Yearly Calendars from Simplicity and Chaos
I've just installed Brad Choate's Perlscript plugin. It enables you to use the Perl scripting language within your templates. I don't know Perl, but Brad's come up with some great plugins and tips that use it, so I've installed it. [Read More]

» Perlscript and Yearly Calendars from Simplicity and Chaos
I've just installed Brad Choate's Perlscript plugin. It enables you to use the Perl scripting language within your templates. I don't know Perl, but Brad's come up with some great plugins and tips that use it, so I've installed it. [Read More]

» Archive by year from Braintags
As I continue defining the information shown on the main page, I find the list of archives by date way too long. I have been thinking about how to solve this problem. The nicest way would be to group all... [Read More]

» Blog Neglect from Train of Thought
This blog, where I intended to journal my life (why people journal their lives, I still haven't figured out...who cares, it's just a life), but, anyway, this blog has just sat here. I have been busy over at My Blog's... [Read More]

» more about annual archives from fuddland
further to my post mentioning annual archives, i've discovered that prolific plugin-writer brad choate had a similar idea, but a... [Read More]

» when in doubt, ask an expert from fuddland
after deciding i couldn't figure out how to get the calendar month headers to link to the corresponding month's archive... [Read More]

» Fancy Web Stuff from Dark Star
So, I have been suffering from Plugin Mania(TM) and have installed and run tons of them in the past month. Thing is, they didn't always work. All of them do now, though. :smile: For a quick re-cap: First I installed... [Read More]

» Various tricks with archive calendars from Sillybean
These tricks apply to the tiny calendars that appear on your home page, not the full-screen monthly archives from my last post How to link to a full day's entries instead of the last one on that day: - Turn... [Read More]

» Archive by year from Brain Tags
As I continue defining the information shown on the main page, I find the list of archives by date way too long. I have been thinking about how to solve this problem. The nicest way would be to group all dates by year and make a dynamical menu showing ... [Read More]

» Redesign Nightmare from Whats Crackin
Still attempting to redesign and I have quite a few errors yet. I did get a Year Archives with MT to work using the PerlScript plugin. Hopefully tomorrow I can finish up the redesign and fix some CSS error's I'm... [Read More]

» Redesign Nightmare from Whats Crackin
Still attempting to redesign and I have quite a few errors yet. I did get a Year Archives with MT to work using the PerlScript plugin. Thank you girlie for the tip! Hopefully tomorrow I can finish up the redesign... [Read More]

» 리뉴얼을 하긴 해야 할텐데... from m i t h r a n d i r . c o . k r
1. 일단 새로운 디자인은 모든 색 지정을 포기한 흰색 위주로 갈 것 같습니다. ColorMatch Remix를 아무리 돌려봐도 답이 안나온다는 것도 이유지만, 아무리 생각해도 제가 처음 생각하던 "낡고 바랜 느낌"을 블로그 사이트에서 구현한다는 건 어렵고, 역시 흰색 바탕의 ... [Read More]

» Lost and Confused from Malibu
Erk! I have been trying for ages to get this year archives plugin to work but am totally lost. As soon as I put the year_view.pl file in the plugins directory it comes up with an internal server error :S... [Read More]

» I just can't figure it out. from Color me pink!
Last year I utilized Brad Choate's year in archives quite successfully and did it for some other people as well. When I tried to add 2003 and 2004, I broke my blog. I did it successfully on another blog, but... [Read More]

13 Comments

Jason Mevius said:

What happens if you don't have any entries in a particular month? For example, what if I wanted to extend the functionality of this plugin to make MT my day planner?

If I enter in a future date (for example, my upcoming Christmas 2002 trip), will this generate the otherwise empty months between now and then?

If so, count me in!

Thanks for all the wonderful work you've done.

Jason

Brad Choate said:

Take a look at:

http://www.bradchoate.com/past/2002.php

And yes, if I were to create entries and set their 'authored on' date to dates in the future, they would appear on the calendar on their respective days.

Quadsk8 said:

Brad,
Would you consider writing a plugin (or instruction with you PerlScript plugin for a Perl-nitwit) for "previous" and "next" facility? As now is only available {MTCalendar month="this"}

I would like to have a three months calendar in my monthly archives.

(If anyone can...)
Thanks for this Year explanation!

Quadsk8 said:

Brad,

I'm interested using the PerlScript plugin with this year_view script.

After I chmod the files I am not able to loginto mt.cgi anymore with a 500 Error.

When I remove the plugins it's ok again.

My ISP uses Apache with SuExec wrapper, could this be conflicting with your PerlScript plugin?

BTW
I could not comment on http://www.bradchoate.com/past/000882.php with following error:
An error occurred:
Rebuild failed: Renaming tempfile '/home/www/bradchoate/past/.new' failed: Renaming '/home/www/bradchoate/past/.new' to '/home/www/bradchoate/past/' failed: Is a directory

Commenting at this location seems to work...

Jake said:

Hey, I am wondering about how one might set up the thermal calendar into a year without hand coding it. It needs to have php run after the script makes 12 calendars... but after it sets them up all of the $hot tags are removed so it can't be checked. Do you know if there is a way around this? I don't know perl very well...

Brian said:

Hi Brad. I was searching for a calendar listing and found this site. I've installed your Perl module (thanks!) but see nothing above about where to actually put the year_view.pl file. Is it under extlib/bradchoate/ or elsewhere? MT doesn't seem to be finding it.

Thanks!

Mostly unrelated... but how did you get your calendar to highlight today's date?

Thanks for the great tips!

-Rick
http://rick.978.org/

Jason said:

Brad,

I tried several other alternatives, with "this" archiving and "that" template, but thanks to your perl module, I have my Yearly archives exactly the way I needed them and all with just one simple template and include module. This is great.

Thanks for the great work!

-Jason

Lisa said:

I have managed to work the caledar (thanks for the great work btw). I dont suppose you could let me know how I turn the month heading into a link. Bit lost with that one! Much appreciated

Zeb said:

Hi Brad, I had a similar problem to Quadsk8 when installing the files for the Year Archives. Alas I am not a coding god so am not too sure how to fix this (or how Quadsk8 fixed it in the end!)

To note was also not too sure which directory to place the year_view.pl file into.

Would really love to use your Year Archives! Hope you can help. Thanks!

Where do I upload each of the files ?

If i copy exactly what u have for the year_view.pl file up there it keeps giving me errors: MT::App::CMS=HASH(0x83189bc) Argument "$mon" isn't numeric in sprintf at lib/MT/Util.pm line 151.
MT::App::CMS=HASH(0x83189bc) Argument "th" isn't numeric in sprintf at lib/MT/Util.pm line 151.
MT::App::CMS=HASH(0x83189bc) Argument "th" isn't numeric in numeric eq (==) at lib/MT/Util.pm line 114.
MT::App::CMS=HASH(0x83189bc) Argument "$mon" isn't numeric in modulus (%) at lib/MT/Util.pm line 30.
MT::App::CMS=HASH(0x83189bc) Argument "th" isn't numeric in subtraction (-) at lib/MT/Util.pm line 38.
MT::App::CMS=HASH(0x83189bc) Argument "$mon" isn't numeric in modulus (%) at lib/MT/Util.pm line 30.
MT::App::CMS=HASH(0x83189bc) Argument "th" isn't numeric in subtraction (-) at lib/MT/Util.pm line 38.
MT::App::CMS=HASH(0x83189bc) Argument "000000-1235959" isn't numeric in numeric lt (

and then if i remove $ everywhere it says:
An error occurred:


Build error in template '2003 Index': Error in tag: Error in tag: Invalid month format: must be YYYYMM

Ok sorry about flooding ure comments but everything is fixed apart from 1 thing, everything looks fine but when you go to http://arvind2100.netfirms.com/blog/archives/2003.html and click a certain date it takes you to e.g. 2003_04_01.html but no such file exists although I have posted on that day, my archives for some reason are stored by their post id ! How do I fix that ???

About

This article was published on July 29, 2002 11:14 AM.

The article previously posted was Pyra: Blogger.

The next article is AOL! 1025 Hours! Free! Yeah, sure..

Many more can be found on the home page or by looking through the archives.

Powered by Movable Type