<mt:SubCategories>
A specialized version of the mt:Categories block tag that respects the hierarchical structure of categories.
<mt:SubCategories top="1">
<!-- do something -->
</mt:SubCategories>
Attributes ¶
Use of either top or category attribute is required.
Bug: As of MT4.261: mt:SubCategories outputs nothing by default Case 100897
category ¶
Specifies a specific category by name for which to return categories.
<mt:SubCategories category="Italian">
<!-- do something -->
</mt:SubCategories>
If two categories have the same label (“Italian” in this case), they can be specified by listing their parent category label followed by the cateory name, separated by a slash:
<mt:SubCategories category="Restaurants/Italian">
<!-- do something -->
</mt:SubCategories>
<mt:SubCategories category="Recipes/Italian">
<!-- do something -->
</mt:SubCategories>
If category label contains a slash (such as “Indian/Pakistani”) surround the value with square brackets:
<mt:SubCategories category="Restaurants/[Indian/Pakistani]">
<!-- do something -->
</mt:SubCategories>
Either top or category is required.
include_current ¶
A boolean attribute controling inclusion of the current category specified in the category attribute in the list.
Bug: As of MT4.261:
mt:SubCategoriesattributeinclude_currentdoesn’t “include” current, rather it limits. Case 100896
sort_method ¶
An advanced usage attribute. A fully qualified Perl method name to be used to sort the categories.
<mt:SubCategories sort_method="Your::Perl::Package::sort_by_entry_count">
<!-- do something -->
</mt:SubCategories>
sort_order ¶
Specifies the sort order of the category labels. Values “ascend” (default) and “descend”. This attribute is ignored if sort_method has been set.
Display a reversed list of top-level categories:
<mt:SubCategories top="1" sort_order="descend">
<!-- do something -->
</mt:SubCategories>
top ¶
If set to 1, displays only top level categories. Same as using TopLevelCategories.
List of top-level categories:
<mt:SubCategories top="1">
<!-- do something -->
</mt:SubCategories>
Examples ¶
Subcategories ¶
List the subcategories of “Category AAA”
<ul>
<mt:SubCategories category="Cat AAA">
<li><a href="<$MTCategoryArchiveLink$>"><$MTCategoryLabel$></a></li>
</mt:SubCategories>
</ul>
Recursive Category List ¶
Recursively list all categories starting with top-level categories, only linking categories that contain entries (using mt:CategoryCount). (Using mt:SubCatIsFirst and mt:SubCatIsLast to condition for the first and last loops respectively):
<mt:SubCategories top="1">
<mt:SubCatIsFirst>
<ul>
</mt:SubCatIsFirst>
<mt:If tag="CategoryCount">
<li>
<a href="<$mt:CategoryArchiveLink$>" title="<$mt:CategoryDescription$>"><mt:CategoryLabel></a>
<mt:Else>
<li>
<$mt:CategoryLabel$>
</mt:If>
<$mt:SubCatsRecurse$>
</li>
<mt:SubCatIsLast>
</ul>
</mt:SubCatIsLast>
</mt:SubCategories>
Display Parent, Sibling and Child Categories ¶
Modify the following for your specific use case.
Use the following mtml on a Category archive to list related categories. List parent and child categories of the current category. If current category has a parent category, then return the parent category and any sub categories. If the current category does not have a parent category then just display subcategories…
<$mt:CategoryLabel setvar="CategoryLabel"$>
<mt:HasParentCategory>
<mt:ParentCategory>
<$mt:CategoryLabel setvar="ParentCategoryLabel"$>
<li>Parent: <a href="<$mt:ArchiveLink$>"><$mt:CategoryLabel$></a></li>
<mt:SubCategories category="$ParentCategoryLabel">
<mt:If tag="CategoryLabel" ne="$ParentCategoryLabel">
<li>Sibling: <a href="<$mt:CategoryArchiveLink$>"><$mt:CategoryLabel$></a></li>
</mt:If>
</mt:SubCategories>
<li>Current: <$mt:Var name="CategoryLabel"$></li>
<mt:SubCategories category="$CategoryLabel">
<mt:If tag="CategoryLabel" ne="$CategoryLabel">
<li>Child: <a href="<$mt:CategoryArchiveLink$>"><$mt:CategoryLabel$></a></li>
</mt:If>
</mt:SubCategories>
</mt:ParentCategory>
<mt:Else>
<mt:SubCategories top="1">
<li>Sibling: <a href="<$mt:CategoryArchiveLink$>"><$mt:CategoryLabel$></a></li>
</mt:SubCategories>
<li>Current: <$mt:Var name="CategoryLabel"$></li>
<mt:SubCategories category="$CategoryLabel">
<li>Child: <a href="<$mt:CategoryArchiveLink$>"><$mt:CategoryLabel$></a></li>
</mt:SubCategories>
</mt:HasParentCategory>
Related ¶
- MTTopLevelCategories
- MTSubCatsRecurse
- Breadcrumbs
- Understanding the Category Listing Code on Learning Movable Type

PlasticMind [typekey.com]
September 8, 2007 10:40 PM | Reply
To create a "breadcrumb" style title using subcategories you can use the following code:
Skot Nelson
September 23, 2007 9:43 AM | Reply
There's a bug in the way categories sort, although I can't find the bug report page (I can find the bug report page for 3.3, but not for 4.)
In the MT Admin Interface categories sort in a case insensitive way. When output to template, the categories sort in a case sensitive way.
This means, that if this is what I see in my interace: Animal Bumble Bee cat Dog emu Frog
when I output a list of categories (in my case using ) I get:
Animal Bumble Bee Dog Frog cat emu
Anil Dash
April 17, 2009 2:10 PM | Reply
Unfortunately,
mt:SubCategoriesdoesn't support theshow_emptyattribute thatmt:Categoriesdoes, where you can choose whether or not to show categories that don't have any entries in them.But! There's a solution using MT's conditional If tags. If the category contains entries, show the Category Label:
JereCoh
May 26, 2009 5:47 PM | Reply
If you want to display a category's peers or siblings, try this:
thirteencentpinball
September 24, 2009 9:25 AM | Reply
In an instance where using a For loop works with the content wrapped in a Categories tag, it doesn't seem to work when wrapped in a SubCategories tag. Is this maybe a bug?