Plugins
: MTCollate 1.1
May 12 2003
| #
| C:26
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.
Version History
- Version 1.1 - January 21, 2004
Added “locale” attribute to MTCollateList.
- Version 1.01 - September 3, 2003
Added “distinct” sort/limit attribute
- Version 1.0 - May 12, 2003
-
1)
Hi,
What to do if the field I want to sort by in the MTCollateList is empty for a particular entry? Right now it just puts the entry at the top of my list. I tried doing sort=”field1 field2” but it looks like it’s just sorting by field2 within each list of entries that match field1, rather than using field2 as a fall back option if there is nothing specified for field1.
Thanks.
-
2)
how come there’s a space after every field I print out?
-
3)
Is it possible to use this to alphabetize lists using a different alphabet than the default english one? Does this support perl“s location features?
-
4)
I’m embarassed to say that the current version (1.0.1) is very much ASCII centric. Case insensitive comparison uses tr/a-z/A-Z/ and it never calls setlocale().
I’ll try to fix this in the next version.
-
5)
Hi
Perfect! I have been looking sorting solution for MT for a while.
Thanks! :)
-
6)
This is a great plugin. I used it to do sorting on the most commented categories on my site. However, it doesn’t seem to sort the fields properly.
-
7)
Hello! I’m hoping you can help me fine tune this a bit. I would like to use this to sort a site with titles of stories and their authors. What I was hoping to do was have it set up so it would go:
Author A:
Title 1
Title 2
Author B:
Title 1
Title 2
etc…
Instead I get either:
Author A:
Title 1
Author A:
Title 2 (etc…), or I with the ‘distinct’ part added below… I only get one author listed on the page.
The “author” names are in the excerpt field, so I have:
<MTCollateCollect>
<MTEntries lastn=”99999”>
<MTCollateRecord>
<MTCollateSetField name=”text”><$MTEntryExcerpt$></MTCollateSetField>
<MTCollateSetField name=”title”><$MTEntryTitle$></MTCollateSetField>
<MTCollateSetField name=”url”><$MTEntryPermalink$></MTCollateSetField>
</MTCollateRecord>
</MTEntries>
</MTCollateCollect>
<MTCollateList lastn=”999999” sort=”excerpt:+:d”>
<MTCollateField name=”text”>:<br>
<a href=”<MTCollateField name=”url”>”><MTCollateField name=”title”></a><br><br>
</MTCollateList>
Thanks!
-
8)
You want to use the MTCollateIfHeader tag to only display the author name once. Try the following listing:
<MTCollateList sort="text:+:i title:+:i">
<MTCollateIfHeader name="text">
<b><MTCollateField name="text">:</b><br>
</MTCollateIfHeader>
<a href="<MTCollateField name="url">"><MTCollateField name="title"></a><br>
</MTCollateList>
Please note that I fixed the sort attribute to use the proper field name, to search case insensitively and to do a secondary sort by title, s.t. each author’s articles are sorted as well.
-
9)
Thanks! That looks like it works wonderfully!
-
10)
Hi Stepan,
I’m afraid I have one more question. I’m trying to utilize both MTCollate and MTPaginate, but I’m having trouble combining them. Could you help me combine them? I have code samples up in this forum entry (don’t want to clutter your page up with long code if I don’t have to!).
Thanks!!
-
11)
You shouldn’t have any problems combinging MTCollate with MTPaginate.
- Collect your collection (MTCollateCollect) before the MTPaginate tag.
- Inside of MTPaginateContent replace your regular listing (i.e. MTEntries) with the collection listing (MTCollateList).
-
12)
Here’s the issue I’m hitting: If the MT tag being used to populate a field — in my case, MTEntryCommentCount — generates a result of 0 (that’s zero), Collate is making that field be empty rather than literally being the character 0.
And that munges the ability to sort by that field. Any ideas?
-
13)
Hi,
I wanted to use MTCollate to list the 20 most recent authors on my site, sorted in order of their last post. So in other words, it would display the last 20 authors who have posted.
Is this possible? Or something like it? I’ve been hacking around with it for the better part of a day, and no luck.
-
14)
Listing the 20 most recent authors shouldn’t be too difficult. The main problem is is that there is no easy way to tell how many entries to look at to make sure that you have at least 20 distinct authors. To be safe, you’ll want to look at a large enough number of entries — say 100 — to account for prolific authors who may post frequently. The following assumes that all authors post to the same blog, you can modify this approach (using MTGlobalListings, for example) if each author has their own blog.
<MTCollateCollect>
<MTEntries lastn="100">
<MTCollateRecord>
<MTCollateSetField name="time"><$MTEntryDate format="%Y-%m-%d %H:%M:%S"$></MTCollateSetField>
<MTCollateSetField name="title"><$MTEntryTitle$></MTCollateSetField>
<MTCollateSetField name="url"><$MTEntryPermalink$></MTCollateSetField>
<MTCollateSetField name="author"><$MTEntryAuthorUsername$></MTCollateSetField>
</MTCollateRecord>
</MTEntries>
</MTCollateCollect>
<ol>
<MTCollateList limit="20" sort="time:- author:distinct">
<li>
<MTCollateField name="author">:
<a href="<MTCollateField name="url">"><MTCollateField name="title"></a>
</li>
</MTCollateList>
</ol>
This will display a list of the 20 most recent authors (without duplicates) with a link to their most recent entry. Note that it’s possible that this list will display fewer than 20 authors if the last 100 posts in the blog were written by less than 20 people. If that’s an issue on your site, you may want to bump up the number of entries that are being looked at in the MTCollateCollect loop.
-
15)
Hello,
I am using MTCollate to create next/previous links for a category archive page. I would like to display the content of a MTCollateList starting with the current category, then display the rest of the names in their correct order. In other words, I would like MTCollate to sort the list starting with a specific name (which is the and then list the others based on another MTCollate field (a sequential id number).
These are my fields:
<MTCollateSetField name="name"><$MTCategoryLabel$></MTCollateSetField>
<MTCollateSetField name="description"><$MTCategoryDescription$></MTCollateSetField>
<MTCollateSetField name="id"><$MTCategoryID$></MTCollateSetField>
<MTCollateSetField name="link"><$MTCategoryArchiveLink$></MTCollateSetField>
Then on each category page, i would like the list to start with the current category(), then sort the rest according to the “id” field.
Is this possible, to define a starting position based on a field value.
Thanks,
-Brett
-
16)
I’m getting a “plugin failed to load” error. Specifically it says syntax error at /home/armchair/public_html/mt/plugins/MTCollate.pl line 544, near “->b uild” BEGIN not safe after errors—compilation aborted at /home/armchair/public_html/mt/plugins/MTCollate.pl line 684. Compilation failed in require at lib/MT.pm line 551.
I have no idea what that means. Please help.
-
17)
Great plugin! I used it to generate a tag cloud display for my categories. Now I’ll figure out a way to adjust font size accordingly, and I’ll have one delicious category listing, so to speak.
http://bluemag.com/idiotbox/
-
18)
Hi,
I tried to install MTCollate(copy the Collate.pl to plugin directory.) on MT3.171 but MT didn’t recognize it. It works fine with MT3.2 on the same server. Does this support MT3.1?
-
19)
I haven’t tested if with MT 3.171, but I see no reason why it shouldn’t work. The plugin was developed for MT2.6x and, as you say, works with MT 3.2. I’d look into what’s different about your MT 3.171 setup. You might want to use MT-Medic to troubleshoot it.
-
20)
Is there a way to use this plugin to list my category archives in order of # of posts rather than alphabetically or by ID?
|
|