Implemented sub-categories in Movable Type 3.121

Over the weekend I was doing some miscellaneous clean-up on the blog and realized that I hadn’t yet checked out one of the nice new features in Movable Type, sub-categories. This makes it easy to logically group categories, something I’d wanted to do (but not badly enough to install a plugin that existed to do this).

After checking out the documentation, I realized that modifying my category archive template to incorporate the new functionality was really simple. If you do category archives in your MT 3.1x site, you can just add this code wherever you want it to show up. Here’s what it does:

  • Checks to see if the category it’s building has a parent; if so, it shows that parent. If there’s no parent category, it skips ahead.
  • Checks to see if the category has any children; if so, it adds them. If there’s no sub-categories, then it skips ahead.

  • Then executes two passes: if there are no parent categories or subcategories, then it prints out a simple statement: No related categories.

Hope this helps!

<b>Parent category:</b><br />
<MTParentCategories exclude_current="1">
<ul><li><a href="<$MTCategoryArchiveLink$>"><MTCategoryLabel></a></li></ul>
<br />
<b>Sub-categories:</b><br />
<a href="<$MTCategoryArchiveLink$>"><MTCategoryLabel></a>
<MTHasNoParentCategory><MTHasNoSubCategories><i>No related categories.</i></MTHasNoSubCategories></MTHasNoParentCategory>

Sub-categories code

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.