-
Notifications
You must be signed in to change notification settings - Fork 36
Melody Cookbook: Create a navigation bar using a category list
A "category list" configuration option allows a theme designer to enable their users to select several categories from a list of the categories in their blog. This is especially useful for things like navigation menus where the structure will be pulled from the hierarchy of the categories.
The following is example of what a category list theme option should look like, at the bare minimum.
categories_in_header:
label: Categories in navigation bar
type: category_list
show_children: 0
hint: Enter a list of categories you want to appear in the navigation bar, separated by commas
tag: CategoriesInHeader
The "show_children" option restricts whether or not child categories can be displayed. Since this is a navigation bar example, it is set to 0 (false) so that only top-level categories are selectable.
This is an example of how to use it. In principle, it should be familiar to anyone who has worked with subcategory recursion.
<mt:CategoriesInHeaderCategories show_empty="0">
<li>
<a href="<$mt:CategoryArchiveLink$>">
<span><$mt:CategoryLabel$></span>
</a>
<mt:SubCategories>
<mt:SubCatIsFirst>
<ul>
</mt:SubCatIsFirst>
<li>
<a href="<$mt:CategoryArchiveLink$>">
<span><$mt:CategoryLabel$></span></a>
<$mt:SubCatsRecurse$>
</li>
<mt:SubCatIsLast>
</ul>
</mt:SubCatIsLast>
</mt:SubCategories>
</li>
</mt:CategoriesInHeaderCategories>
Category list tags can be accessed as either a function tag or a block tag, like the other specialized tags ConfigAssistant builds. The function tag form (mt:CategoriesInHeader in this example) returns a comma-delimited list of category ID numbers. As a block tag (example used here), it creates a category context where category tags can be used.