If you want to sort your categories in some customized order — i.e., not alphabetically, which is the MT default — there are some solutions. I’ve tracked down three different solutions.
(Note that I am now running MT 3.35, and I’m not sure Solution #3 below works in anything below version 3.3x.)
Disclaimer: I’ve lifted this solution from a thread in the MT forums, and copied it. I don’t claim to understand the regular expression at all. It just works.
Here’s what you do:
Somewhere in your code, add this line:
<MTAddRegex name="RemoveSortNumber">
s|^([\d\.]*\s*)||
</MTAddRegex>
Now, when you use the <MTCategories> tag, add the following argument
<$MTCategoryLabel regex="RemoveSortNumber"$>
Basically, this is stripping digits from the start of the line.
Pros
Cons
Note that much the same thing can be done with the superb MT-Macros plugin. That’s really a three-and-halfth solution, because, as I see it, it’s only a refinement of the RegEx solution.
Now here’s the trick. Over at his own plugin forums at Movalog, there’s a thread where Arvind tells of an undocumented sort feature in Version 2.0RC1 of CustomFields. You can add an argument to the MTCategories tag and force a sort by a custom field. Here’s what Arvind says:
this is a new feature (that I haven’t publiciszed or documented at all for lack of time) introduced with v2.0. To resort by a custom field (called “Foo Bar”), the following syntax is used (on MTEntries, MTCategories or MTEntries):
sort_by="CUSTOMFIELD:Foo Bar"
sort_order="ascend|descend"
So supposing you wanted to resort categories by the Foo Bar field in descending order:
<MTCategories sort_by="CUSTOMFIELD:Foo Bar"
sort_order="descend">
So in our case, with the CustomField CategoryNum, the code would be:
<ol>
<MTCategories sort_by="CUSTOMFIELD:CategoryNum"
sort_order="ascend" show_empty="1">
<li><b><$MTCategoryLabel$></b>
<br /><$MTCategoryDescription$></li>
</MTCategories></ol>
Essentially, all you are doing is sorting by the custom field, and then displaying as normal.
Pretty nifty.
Pros
Cons
This one’s sort of homegrown. Here’s what you do.
Now, instead of using the <MTCategoryLabel> tag, you use the <MTCategoryBasename> tag, passing it through any formatting filters (for upper/lower case, etc). For example:
<ol><MTCategories show_empty="1">
<li><span style="text-transform: capitalize;
font-weight:bold;">
<a href=<$MTCategoryArchiveLink$>">
<$MTCategoryBasename$>
</a></span><br />
<Does this work?></li>
</MTCategories></ol>
Basically, you’ve swapped the category label and the category basename. Now MT sorts categories by the label, in the numbered sequence you’ve set up, but uses the basename of each category for display.
Pros
Cons
my_favourite_things. That’s really ugly. So you’d have to either limit yourself to one word categories, or run MT-Macros or the Regex plugin to get rid of the underscores.My choice? Option 2, without a doubt. Arvind rules!