Go to main content

If article category




The if_article_category tag is a conditional tag and always used as an opening and closing pair, like this…

    …conditional statement…

It will execute the contained statement if the category name associated with a particular article (Category1 or Category2) matches the values of the name and number attributes. Should be used in ‘article’ type Textpattern Form templates.


Tag will accept the following attributes (case-sensitive) as well as the global attributes :

Comma-separated list of category names (not titles) to match. Note the category name is specified in lower case regardless of how you typed its title in the Categories panel. Also note that if you had called your category ‘My Category Name’ it becomes my-category-name when used in tags.
Default: unset.
Match category in Category1 or Category2 (or both).
Values: 1 or 2.
Default: unset, causing both categories to be matched against the specified name.


Example 1: Display matched category

<txp:if_article_category name="prose" number="1">
        <txp:category1 />

If the Category1 assigned to the article is ‘Prose’, the category is displayed. Note that the category name is used in this tag, which may be different to its displayed category Title. When categories are created, Textpattern converts them to lowercase and replaces spaces with hyphens. So, for example, ‘My Category’ has a name my-category.

Other tags used: category1.

Example 2: Using the tag with else

<txp:if_article_category name="algebra" number="1">
    <p>Fun with algebra</p>
<txp:else />
        <a href="/">Home</a>

Displays the welcome text if the category and category number match the given values, or shows a default link otherwise.

Other tags used: else.

In an article form, put the following set of conditionals for each category you want to look for:

<txp:if_article_category name="yourcategory" number="1">
    <txp:article_custom category="yourcategory" sort="Posted asc" wraptag="ul" break="li">
            <txp:title />

Lists articles of the same category as the current article’s Category1.

Other tags used: article_custom, else, title, permlink.

If you notice any kind of problem with this page's construction or content (outdated information, typos, broken links, or whatever), open an issue to have it sorted. Or have a go at it yourself. :)