If category
Contents
Syntax
<txp:if_category>
The if_category tag is a conditional tag and always used as an opening and closing pair, like this…
<txp:if_category>
…conditional statement…
</txp:if_category>
The tag will execute the contained statements if the name attribute matches a category search value, or the list is an article list by category.
Should be used in a page template; if checking the category in an article form, use if_article_category.
Attributes
Tag will accept the following attributes (case-sensitive) as well as the global attributes :
category="category"v4.7.0+- Category name. 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: the current listing category, if any.
name="category"- Comma-separated list of category names.
- Default: unset, which determines whether ‘‘any’’ category listing is being viewed.
parent="category or integer"v4.7.0+- Comma-separated list of category names or an integer. In the first case, the tag will check if
categoryor some of its ancestors belong to theparentlist. In the second case, the tag will check ifcategory’s ancestor of this generation belongs to thenamelist. - Default: unset.
type="context"v4.3.0+- Textpattern context to check against. You can choose from the following contexts (set to empty to include all contexts):
articleis this an article category list?
imageis this an image category list?
fileis this a file category list?
linkis this a link category list? - Default:
article.
Examples
Example 1: Display info depending on list category
<txp:if_category name="prose">
<p><txp:author /></p>
</txp:if_category>
Displays the author’s name if the article list is of category prose.
Other tags used: author.
Example 2: Use tag with else
<txp:if_category name="prose">
<p><txp:category /></p>
<txp:else />
<h3><txp:site_name /></h3>
</txp:if_category>
Displays the category name if the article list is of category prose, otherwise show the site’s name.
Other tags used: category, else, site_name.
Example 3: Display an appropriate heading
<txp:if_category>
<h3>Articles in category <txp:category title="1" /></h3>
<txp:else />
<h3>All articles</h3>
</txp:if_category>
Displays an appropriate heading for both category and non-category pages.
Other tags used: category, else.
Example 4: Display a category/article list
Given the defined article categories: prose, poetry, and opinions.
<txp:category_list label="Category Navigation" wraptag="p" />
<txp:if_category name="prose">
<txp:recent_articles limit="25" break="li" wraptag="ol" label="Prose" category="prose" />
</txp:if_category>
<txp:if_category name="poetry">
<txp:recent_articles limit="25" break="li" wraptag="ol" label="Poetry" category="poetry" />
</txp:if_category>
<txp:if_category name="opinions">
<txp:recent_articles limit="25" break="li" wraptag="ol" label="Opinions" category="opinions" />
</txp:if_category>
Shows a category list and, underneath it, a list of related articles in the currently selected category. Changing the category using the list changes the related articles underneath.
Other tags used: category_list, recent_articles.
Example 5: Check if ‘cat’ is descendant of ‘animal’
<txp:if_category category="cat" parent="animal">
<p>Cat is an animal.</p>
</txp:if_category>
Example 6: Check if ‘anakin’ is the father of ‘luke’
<txp:if_category category="luke" parent="1" name="anakin">
<p>The test is positive - I am your father!</p>
</txp:if_category>
Genealogy
Version 4.7.0
category and parent attributes added.
Version 4.3.0
type attribute added.