Archive Fun #
One thing that had been bothering me about my current layout was that the monthly archive list looked so disheveled and ragged. I thought that a hierarchical view, with each month under its respective year, would be a lot better. After a bit of exploration, it appeared that I couldn't get that effect with the regular MT tags, and I wasn't feeling adventurous enough to write my own plugin. Therefore, the only option left was to see what I could put together using existing plugins.
After some digging around at the MT Plugin Directory, I came across MTMacro and ArchiveYear (actually, that's a bit of a lie, I had used MTMacro earlier, together with MTEntry in order to implement this tip on entry linking). The plan was very simple, define a macro like this:
<MTMacroDefine name="yearArchive" tag="yearArchive">
<MTMacroAttr name='year'><br />
<MTArchiveYear order="descend" skip="yes" columns="1" year="[MTMacroAttr name='year']" >
<MTArchiveYearIfEntries>
<span class="monthArchiveList">
<a href="archives/<$MTArchiveDate format="%Y_%m"$>.html">
<$MTArchiveDate format="%B"$>
</a>
</span><br />
</MTArchiveYearIfEntries>
</MTArchiveYear>
</MTMacroDefine>
(I don't know why I had to use <span>
's instead of <div>
's, but if I hadn't then the padding wasn't taking effect (though other CSS attributes like border
did work)). With that macro in place, it can be invoked like this in place of my regular monthly archive list:
<yearArchive year="2004" /> <yearArchive year="2003" /> <yearArchive year="1999" /> <yearArchive year="1998" />
This requires me to add a new macro call for each year, but I think I can manage to remember that. In any case, this all seems great, but in fact it didn't work. It turned out that MTArchiveYear didn't support embedded expressions in its year
parameter. Seeing as I had to get my hands dirty with plugin code, I took the shortest possible path. Since MTEntry did support embedded expressions, I simply lifted its parsing calls and added them to the archive_year
function that implemented the tag. The diffs are here.
An alternative would be to keep using the old MTArchiveList based archive, see if the previous entry's year can be stored in a variable, and then that variable is different from the current month's year, insert some sort of header. To be tried some other time.
P.S. Just to show how prophetic Peopleware can be, even for small things like this: I expected the entire thing to take one hour, and it took two.
Post a Comment