« May 2005 | Main | August 2005 »

June 27, 2005

Movable Type and Category Orders

So it turns out that the default order in Movable Type for categories is alphabetical, which if fine for some things, but not so hot for others. I spent the last few hours changing this so I could better organize my categories according to my priorities

The change is not that hard and basically involves installing Brad Choate's regular expression plugin and editing a few lines in your templates. Here is the process expanded a bit from the original reference that I found with google.

  1. Download and install Brad Choate's regular expression plugin for Movable Type. The readme.txt has the install details with basic usage. The most chalenging aspect was finding where Movable Type is installed on our systems.
  2. Link the main index template to a local file that you can edit. Note: order is important on this. Link the file first, then copy in your new template or make changes.
  3. Rename all of your categories with a fixed prefix that when ordered alphabetically will result in the order you want for the categories. For example, a category prefixed with CatA: will come before a category prefixed with CatB:. You get the point I hope.
  4. Edit your local template file (for me is is the main index template) to use regular expressions to remove the prefix from the categories in the generated HTML labels. I do not have the patience to HTML'lize the code, so here is a plain text file with it.
<!-- +++++ egm 06/27/2005 --> <!-- --> <!-- Added Brad Choate's regex pluggin to break alphabetical --> <!-- order on categories: --> <!-- http://www.bradchoate.com/weblog/2002/07/27/mtregex --> <!-- Define a regular expression to strip the preceding "Cat.:" --> <!-- tag used to define the order of the categories. --> <MTRegexDefine name="catrm">s/^Cat.://gi</MTRegexDefine> <MTCategories> <!-- Output categories that match the "Cat.:" prefix --> <MTIfMatches var="CategoryLabel" pattern="m/(Cat.:)/i"> <a name="<$MTCategoryLabel regex="catrm"$>" ></a> <b><$MTCategoryLabel regex="catrm"$></b><br> <ul> <MTEntries lastn="1" sort_order="descending"> <li> <a href="<$MTEntryPermalink$>"><$MTEntryTitle$></a> [<$MTEntryCommentCount$> comments; posted <$MTEntryDate format="%e %b"$>] </li> </MTEntries> <MTEntries lastn="3" offset="1" sort_order="descending"> <li><a href="<$MTEntryPermalink$>"><$MTEntryTitle$></a> [<$MTEntryCommentCount$>; <$MTEntryDate format="%e %b"$>] </MTEntries> <li>All <a href="<$MTCategoryArchiveLink$>"> <$MTCategoryLabel regex="catrm"$$> entries </a> </li> </ul> </MTIfMatches> </MTCategories> <!-- ----- end modifications by egm -->

Posted by egm at 01:44 PM | Comments (0)