MTCollate 1.1
May 12, 2003
- updated February 8, 2006
(Download)
The listing tags that are built in to MovableType (MTEntries, MTCategories, etc.) have limited number of sorting options. For example, while you may sort entries chronologically, it is not possible to sort them descending by date, while ascending by time. Nor is it possible to intermingle different types of listings, for example a list of comments and trackback pings.
The MTCollate plugin gives you great flexibility in sorting listings (for example, descending by date while ascending by time) and allows you to list heterogeneous data (for example, entries, comment and trackback pings together sorted by time). It even allows you to sort by non-continuous values (for example, categories could be sorted by other than name or id).
How MTCollate Works
MTCollate works by building a virtual collection of records using the MTCollateCollect, MTCollateRecord and MTCollateSetField container tags. For example, the following code would create a collection containing 20 records, each of which consists of the fields “type”, “date”, “time”, “title”, “text” and “url”. Note that the first 10 records are filled with information from most recent entries while the next 10 records are filled with information from most recent comments.
<MTCollateCollect>
<MTEntries lastn="20">
<MTCollateRecord>
<MTCollateSetField name="type">Entry</MTCollateSetField>
<MTCollateSetField name="date"><$MTEntryDate format="%Y-%m-%d"$></MTCollateSetField>
<MTCollateSetField name="time"><$MTEntryDate format="%H:%M:%S"$></MTCollateSetField>
<MTCollateSetField name="text"><$MTEntryExcerpt$></MTCollateSetField>
<MTCollateSetField name="title"><$MTEntryTitle$></MTCollateSetField>
<MTCollateSetField name="url"><$MTEntryPermalink$></MTCollateSetField>
</MTCollateRecord>
</MTEntries>
<MTComments lastn="20">
<MTCollateRecord>
<MTCollateSetField name="type">Comment</MTCollateSetField>
<MTCollateSetField name="date"><$MTCommentDate format="%Y-%m-%d"$></MTCollateSetField>
<MTCollateSetField name="time"><$MTCommentDate format="%H:%M:%S"$></MTCollateSetField>
<MTCollateSetField name="text"><$MTCommentBody$></MTCollateSetField>
<MTCommentEntry>
<MTCollateSetField name="title">Comment for <$MTEntryTitle$></MTCollateSetField>
<MTCollateSetField name="url"><$MTEntryPermalink$></MTCollateSetField>
</MTCommentEntry>
</MTCollateRecord>
</MTComments>
</MTCollateCollect>
Once a collection has been built, its contents can be displayed using the MTCollateList and MTCollateField tags. MTCollateIfHeader and MTCollateIfFooter tags can be used to separate records that are listed, similar to MTDateHeader and MTDateFooter. For example, the following code displays 10 records for the previous collection, sorted descending by date and ascending by time within each day:
<MTCollateList limit="10 date:- time:-" sort="date:- time:+">
<MTCollateIfHeader name="date">
<div class="date">
<MTCollateField name="date">
</div>
<div class="time">
</MTCollateIfHeader>
<MTCollateField name="time">:
<a href="<MTCollateField name="url">"><MTCollateField name="title"></a>
<div><MTCollateField name="text"></div>
<MTCollateIfFooter name="date">
</div>
</MTCollateIfFooter>
</MTCollateList>
MTCollateTags
- MTCollateCollect
Container tag that defines a collection of records. It does not display any text.
- name=”collection name”
This optional parameter assigns a name to the collection. You can have multiple collections as long as their names are unique.
- MTCollateRecord
Container tag that defines a record in the collection. Must be located inside the MTCollateCollect tags.
- MTCollateSetField
Container tag that sets a field in the current collection record. Must be located inside MTCollateRecord tags.
- name=”field_name”
This required attribute specifies the name of the field. The name should only consist of numbers, letters and underscore characters.
- MTCollateList
Container tag that displays the records in an existing collection.
- MTCollateField
Displays the value of the specified field in the current record. If the field does not exist, an empty string is displayed.
- name=”field_name”
Specifies the name of the field to be displayed.
- MTCollateIfHeader
Container tag that displays its contents if this is the first record in the list, or if the value of the specified field differs from the same field in the preceding record.
- name=”field_name”
Specifies the name of the field to be compared.
- MTCollateIfFooter
Container tag that displays its contents if this is the last record in the list, or if the value of the specified field differs from the same field in the following record.
- name=”field_name”
Specifies the name of the field to be compared.
- MTCollatePrevious
Container tag that displays its contents in the the context to the preceding record, if any.
- MTCollateNext
Container tag that displays its contents in the the context to the following record, if any.