Welcome to MTTags.com. Hopefully, you'll discover that this a really easy place to find information about Movable Type Template Tags. If you think we could be doing something better, please let us know! If this is your first time here, be sure to stop by the information desk, because we've got a growing todo list that might already include what you were about to suggest.

<MTIfCategory>

A conditional block which tests attributes of the category currently in context and outputs its contents on a match.

This tag can be used anywhere where there is a category context:

  • Within an MTEntries loop
  • In a category archive template
  • Within an MTCategories loop
  • Etc

Required attributes

  • name - Name of category for conditional test
  • label - Alias of name attribute above

Optional attribute

  • type - Tests for the assignment type for the category, accepting values of primary and secondary.

NOTE: There is currently a known issue related to this in that the value of 'secondary' is not accepted by the type attribute.

Example code

Conditional output based on category:

<MTIfCategory label="important">
    This is important
<MTElse>
    Misc is not so important
</MTElse>
</MTIfCategory>

This can be used in conjuction with CSS rules to display things differentially. This adds a class attribute of featured to the entry title h2 tag if the category of the entry is "Featured":

<h2 <MTIfCategory name="Featured">class="featured"</MTIfCategory>>
   <MTEntryTitle>
</h2>

Below is a full example testing for not only category assignment, but also the type of assignment.

<MTIfCategory label="misc" type="primary">

    Misc is the primary category
<MTElse>
    <MTIfCategory label="misc" type="secondary">
        Misc is the secondary category
    <MTElse>
        Misc is neither a primary not secondary category
    </MTElse>
    </MTIfCategory>

</MTElse>
</MTIfCategory>