tips and tricks for movable type

two calendars reverse sort
February 01, 2003

Here's some code I've been meaning to post for a while (though I can't claim complete credit for it, as it was just me patching together other stuff in this support forum thread). It allows you to display two calendars together in reverse order (oldest first).

You may already know that you can surround your MT Calendar tags with an MTArchiveList tag to display multiple calendars (sample code courtesy of Kristine):

<table width="500" border="0" align="center"><tr>
<MTArchiveList lastn="2" archive_type="Monthly">
<td width="250">

All the other center stuff from the other post besides the MTArchiveList Container

</td>
</MTArchiveList>
</tr></table>

The 2 tells MT how many calendars you want to display. But, because MTArchiveList doesn't offer any sort options, the calendars will appear from newest to oldest. If you want to reverse that, here's the code.

Two Calendars in Reverse Order, Side by Side:

<table width="500" border="0" align="center"><tr>
<?php
<MTArchiveList lastn="2" archive_type="Monthly">
$monthlyarchivereverse[] =
"<td width=\"250\">
<table border=\"0\" cellspacing=\"4\" cellpadding=\"0\" summary=\"Monthly calendar\">
<caption><$MTArchiveDate format="%B %Y"$></caption>
<tr>
<th abbr=\"Sunday\" align=\"center\">Sun</th>
<th abbr=\"Monday\" align=\"center\">Mon</th>
<th abbr=\"Tuesday\" align=\"center\">Tue</th>
<th abbr=\"Wednesday\" align=\"center\">Wed</th>
<th abbr=\"Thursday\" align=\"center\">Thu</th>
<th abbr=\"Friday\" align=\"center\">Fri</th>
<th abbr=\"Saturday\" align=\"center\">Sat</th>
</tr> <MTCalendar month="this">
<MTCalendarWeekHeader><tr></MTCalendarWeekHeader>
<td <MTCalendarIfToday>bgcolor=\"#EEEEEE\"</MTCalendarIfToday> align=\"center\">
<MTCalendarIfEntries><MTEntries lastn="1"><a href=\"<$MTEntryLink$>\"><$MTCalendarDay$></a></MTEntries>
</MTCalendarIfEntries>
<MTCalendarIfNoEntries><$MTCalendarDay$></MTCalendarIfNoEntries>
<MTCalendarIfBlank> </MTCalendarIfBlank></td>
<MTCalendarWeekFooter></tr></MTCalendarWeekFooter>
</MTCalendar>
</table>
</td>";
</MTArchiveList>
$monthlyarchive = array_reverse($monthlyarchivereverse);
foreach($monthlyarchive as $temp) {
echo $temp;
}
?>
</tr></table>

View a demo here.

Two Calendars in Reverse Order, Top to Bottom:

<div align="center" class="calendar">
<?php
<MTArchiveList lastn="2" archive_type="Monthly">
$monthlyarchivereverse[] =
"<table border=\"0\" cellspacing=\"4\" cellpadding=\"0\" summary=\"Monthly calendar\">
<caption><$MTArchiveDate format="%B %Y"$></caption>
<tr>
<th abbr=\"Sunday\" align=\"center\">Sun</th>
<th abbr=\"Monday\" align=\"center\">Mon</th>
<th abbr=\"Tuesday\" align=\"center\">Tue</th>
<th abbr=\"Wednesday\" align=\"center\">Wed</th>
<th abbr=\"Thursday\" align=\"center\">Thu</th>
<th abbr=\"Friday\" align=\"center\">Fri</th>
<th abbr=\"Saturday\" align=\"center\">Sat</th>
</tr>
<MTCalendar month="this">
<MTCalendarWeekHeader><tr></MTCalendarWeekHeader>
<td <MTCalendarIfToday>bgcolor=\"#EEEEEE\"</MTCalendarIfToday> align=\"center\">
<MTCalendarIfEntries><MTEntries lastn="1"><a href=\"<$MTEntryLink$>\"><$MTCalendarDay$></a></MTEntries>
</MTCalendarIfEntries>
<MTCalendarIfNoEntries><$MTCalendarDay$></MTCalendarIfNoEntries>
<MTCalendarIfBlank> </MTCalendarIfBlank></td>
<MTCalendarWeekFooter></tr></MTCalendarWeekFooter>
</MTCalendar>
</table>
<br /><br />";
</MTArchiveList>
$monthlyarchive = array_reverse($monthlyarchivereverse);
foreach($monthlyarchive as $temp) {
echo $temp;
}
?>
</div>

View a demo here.

Comments

ohmigod ohmigod! girls, this place is looking good!!

by monica | 02.06.03 05:10 PM

Maybe someday I will use this !

by iced glare | 02.12.03 08:46 PM

Okay simple question for most of you I am sure, but one that I can't yet get my head round. I've just started an online diary at www.markusrandall.com - but I want to set it up so that you scroll through entries for a given day in chronical order i.e. not most recent first, but earliest first. So, 9am comes up before 10pm. Any ideas how to simply switch this over?

by Damian | 08.01.03 06:55 PM

Okay - I worked it out - scrap that request!

by Damian | 08.01.03 07:03 PM

So I'm kinda happy with one calendar. When I'm annoyed is days such as this when June is now totally empty with no entries. What I really want is to see the last five or six weeks in entries from with today as the ending date. Doesn't that seem more useful? Just a thought...

by Gary LaPointe | 06.01.04 02:00 AM

brilliant. this is exactly what i was lookig for. you've saved me a night of frustration and using the lord's name in vain.

by patrick | 06.23.04 11:36 PM

is there a way to do it without php? thanks!

by sugi_grl [TypeKey Profile Page] | 04.18.05 05:56 PM

Post a comment

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

TrackBack: 1
(URL: http://www.thegirliematters.com/sf/mt-track.cgi/138)

» Various tricks with archive calendars
Excerpt: These tricks apply to the tiny calendars that appear on your home page, not the full-screen monthly archives from my
Weblog: Sillybean
Tracked: 02.14.03 01:57 PM