<mt:IfCategory>

A conditional tag used to test for category assignments for the entry in context, or generically to test for which category is in context.

Attributes:

  • name (or label; optional)

    The name of a category. If given, tests the category in context (or categories of an entry in context) to see if it matches with the given category name.

  • type (optional)

    Either the keyword "primary" or "secondary". Used to test whether the specified category (specified by the name or label attribute) is a primary or secondary category assignment for the entry in context.

Examples:

    <mt:IfCategory>
        (current entry in context has a category assignment)
    </mt:IfCategory>

    <mt:IfCategory type="secondary">
        (current entry in context has one or more secondary category)
    </mt:IfCategory>

    <mt:IfCategory name="News">
        (current entry in context is assigned to the "News" category)
    </mt:IfCategory>

    <mt:IfCategory name="News" type="primary">
        (current entry in context has a "News" category as its primary category)
    </mt:IfCategory>
This page was last updated on 2008-06-17, 17:25.  

3 Notes

Hi there!

Is it possible to give the attributes a value with "MTGetVar" ?

Like this?

<MTIfCategory label="<$MTGetVar name="ThisBlog"$>">

Cheers kai

You can use this tag to display all entries EXCEPT those in a certain category, which is something that was really clumsy before and required plugins and scripts to make happen. For example:

<mt:Entries>
    <mt:IfCategory label="Special Events"> 
    <mt:else>
    <li><a href="<$mt:EntryPermalink$>"><$mt:EntryTitle$></a></li>
    </mt:IfCategory>
</mt:Entries>

...will return a list of all entries EXCEPT those in the Special Events category.

Conversely, you could use a different set of parameters and have the Special Events Category display differently than everything else. As a simple example:

<mt:Entries>
    <mt:IfCategory label="Special Events">
    <li><a href="<$mt:EntryPermalink$>"><strong><$mt:EntryTitle$></strong></a></li> 
    <mt:else>
    <li><a href="<$mt:EntryPermalink$>"><$mt:EntryTitle$></a></li>
    </mt:ifcategory>
</mt:Entries>

...will return a list of all entries and all the entries in the Special Event category will be in bold type.

@kai -- yes, this is possible. Here's an example:

<$mt:Var name="label_name" value="foo"$>
<mt:IfCategory label="$label_name">
    true if $label_name = foo
</mt:IfCategory>

Leave a note

Have a question, please use the MT Forums. Notes sumbitted here should pertain to tips & hints regarding documentation.