The Movable Type User Manual

NOTE: This documentation is for Movable Type 3.2. If you are using a newer version, please see the documentation for Movable type 3.3x or Movable Type Enterprise.

« Displaying Weblog Data | Up | Publishing Content When a Conditional is False »

Chapter 3: Templates and Layout

Displaying a Calendar Layout

Problem

You want to create a calendar layout in your template.

Solution

Use the template tags prefixed with MTCalendar.

Discussion

Movable Type includes a collection of template tags prefixed with MTCalendar; these can be used for creating calendar layouts that serve either navigational or display purposes. MTCalendar tags are sufficiently generic to create calendars in many different formats; however, HTML tables are the most common,

  • MTCalendar

    MTCalendar is a container tag representing a calendar month that lists a single calendar "cell" in the calendar display. A calendar cell is either a day of the month or a blank; this is used to represent a day in a different month.

    This tag takes an optional attribute month, which, if present, specifies the desired calendar month and year. If the value of this attribute is the string this, the calendar will be created in the surrounding date context; this means that, for example, in an archive template, you can use:

        <MTCalendar month="this">
        ...
        </MTCalendar>

    This represents the month of the archive currently being viewed. This will work for Individual, Daily, Weekly, and Monthly archives, but not for Category archives.

    If the value of the month attribute is last, the calendar will be created for the previous month, relative to the current date.

    If you'd like to create a calendar for a specific month, you can use the month attribute to specify the exact month and year in YYYYMM format. For instance to display the calendar for April 2005 the month attribute would have a value of "200504."

    If the month attribute is not provided, the calendar will display the current month.

    If you would like to only display entries from a certain category, you can optionally specify the category attribute, giving it the category label.

        <MTCalendar month="200504" category="Foo">
        ...
        </MTCalendar>
  • MTCalendarDay

    The numeric day of the month for the cell.

  • MTCalendarIfEntries

    A conditional tag that will display its contents if there are any entries for this day in the weblog.

  • MTCalendarNoEntries

    A conditional tag that will display its contents if there aren't entries for this day in the weblog. This tag predates to introduction of MTElse that could be used with MTCalendarIfEntries to replace this tag.

  • MTCalendarIfBlank

    A conditional tag that will display its contents if the current calendar cell is for a day in another month.

  • MTCalendarWeekHeader

    The contents of this tagset will be displayed before a calendar week is started.

  • MTCalendarWeekFooter

    The contents of this tagset will be displayed after a calendar week is ended.

Prior to version 3.2, a calendar display was included in the Main Index template of the default template set. This markup has since been removed to speed up rebuilding times.

The following is the layout that was included in the default templates but with the styles updated for Movable Type 3.2 (thanks to Arvind Satyanarayan).

<h2 class="module-header"><$MTDate format="%B %Y"$></h2>
<div class="module-content">
    <table summary="Monthly calendar with links to each day's posts">

        <tr>
        <th abbr="Sunday">Sun</th>
        <th abbr="Monday">Mon</th>
        <th abbr="Tuesday">Tue</th>
        <th abbr="Wednesday">Wed</th>
        <th abbr="Thursday">Thu</th>
        <th abbr="Friday">Fri</th>
        <th abbr="Saturday">Sat</th>
        </tr>

<MTCalendar>
<MTCalendarWeekHeader>
        <tr>
</MTCalendarWeekHeader>
            <td>
<MTCalendarIfEntries>
<MTEntries lastn="1">
                <a href="<$MTEntryPermalink$>"><$MTCalendarDay$></a>
</MTEntries>
</MTCalendarIfEntries>
<MTCalendarIfNoEntries>
                <$MTCalendarDay$>
</MTCalendarIfNoEntries>
<MTCalendarIfBlank> </MTCalendarIfBlank>
            </td>
<MTCalendarWeekFooter>
        </tr>
</MTCalendarWeekFooter>
</MTCalendar>
</table>
</div>
</div>

As you can see, calendar layouts get complex rather quickly. The computation of the calendar display can significantly extend the processing time involved in rebuilding pages. It is generally recommended that these tags be applied judiciously, if at all, to your templates.

For the full list and descriptions of all calendar tags see Appendix A.

Comments

Thanks for posting this. Arvind's calendar code should either have a

div class="module"
tag at the top or one fewer
/div
tags at the bottom.

Submit Feedback on This Article

Your comments on how we can improve this article are appreciated; but please do not use the feedback form to submit support requests or question. We will not respond to or publish such queries submitted through this form. If you have a technical question or problem, visit Movable Type Support.

Six Apart
Makers of weblog software and services for individuals, organizations and businesses.
This website is powered by Movable Type.