Article
MT3 Subcategories update
Last night, I wrote that subcategories in MovableType 3 weren’t working properly. Or, at least weren’t working as I expected them to.
The proper template code is much simpler, it turns out. Here’s what I should have done:
1 <MTSubCategories>
2 <h4><$MTCategoryLabel$></h4>
3 <ul>
4 <MTSubCategories>
5 <li><$MTCategoryLabel$></li>
6 </MTSubCategories>
7 </ul>
8 <MTSubCategories>
That’s looks a lot easier than this, doesn’t it?
Two problems
There were two problems at work in my ill-fated attempt to use subcategories:
My frustration got in the way of thinking. When I started to work on this, I became frustrated because the documentation for subcategories is so vague (more on this later). As time passed and no solution was in sight, my brain just stopped working.
Documentation for subcategories is very poor. Most of the MovableType documentation is pretty good, but the bit on subcategories (which was lifted directly from documentation for David Raynes’ SubCategories plugin) is difficult to understand. I am not trying to pick on David here (because he gives a lot to the MT community and is a very nice guy), but this was clearly written by a plugin developer. That is, from the perspective of someone who just wrote this plugin and not the perspective of someone who might be using it for the first time.
Let me provide an example of what I mean:
MTSubCategories MTSubCategories is a replacement for MTCategories that will respect the hierarchical structure of your categories.
Now this is a pretty critical template tag if you are going to use subcategories. Bit by bit, here’s my understanding:
MTSubCategories is a replacement for MTCategories…
Okay, this is pretty clear. Looks like it mimics the behavior of MTCategories — i.e. you can use all the same arguments, sub-tags, etc. But then we get this:
…that will respect the hierarchical structure of your categories
Respect them? What on earth does that mean? (Seriously, I don’t even know what to think.)
Worse yet, when I compared the basic output of MTCategories to MTSubCategories (by listing the name of each category), it was the same. In an act of severe neglect, Six Apart doesn’t even include example code for using this tag. At least David does that, but his isn’t a lot of help:
Here is the template code to generate a list of categories using nested unordered lists:
1 <MTSubCategories>
2 <MTSubCatIsFirst><ul></MTSubCatIsFirst>
3 <li>
4 <MTCategoryLabel>
5 <MTSubCatsRecurse>
6 </li>
7 <MTSubCatIsLast></ul></MTSubCatIsLast>
8 </MTSubCategories>
I took two years of computer science, but never managed to figure out recursive functions (line 5). It’s probably not the most manageable concept to use in your first example.
In the end, everything turned out fine. I got my subcategories, Noel got his snotty comment in, and I learned a good lesson.
But now it’s time for Six Apart’s lesson: Pay attention to your documentation. Pay a lot of attention. Because for a significant number of your users (those who aren’t plugin developers themselves), it’s their foundation for understanding MovableType.