<txp:if_category /> container tag, 2 attributes

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 (?c=category)

Should be used in a page template; if checking the category in an article form, use if_article_category.

attributes

name="unset" 
  • Comma-separated list of category names. Note the category name is specified in lower case regardless of how you typed its title in the Category tab. Also note that if you had called your category My Category Name it becomes my-category-name when used in tags
type="article" 
  • Textpattern context to check against. You can choose from the following contexts:
    • article is this an article category list?
    • image is this an image category list?
    • file is this a file category list?
    • link is this a link category list?

genealogy

Version 4.3.0

  • type attribute added
<txp:if_category /> 4 examples

Display info depending on list category

<txp:if_category name="prose">
<p><txp:author /></p>
</txp:if_category>

What this does…
Displays the author’s name if the article list is of category “Prose”.

Other tags used: author

Use tag with else

<txp:if_category name="prose">
   <p><txp:category /></p>
<txp:else />
   <h3><txp:site_name /></h3>
</txp:if_category>

What this does…
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

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>

What this does…
Displays an appropriate heading for both category and non-category pages.

Other tags used: category, else

Display a category / article list

Given the defined article categories: Prose, Poetry, and Opinions.

<txp:category_list label="Category Navigation" wraptag="p" class="list" />
<txp:if_category name="prose">
<txp:recent_articles label="Prose" limit="25" break="br" wraptag="p" class="list" category="prose" />
</txp:if_category>
<txp:if_category name="poetry">
<txp:recent_articles label="Poetry" limit="25" break="br" wraptag="p" class="list" category="poetry" />
</txp:if_category>
<txp:if_category name="opinions">
<txp:recent_articles label="Opinions" limit="25" break="br" wraptag="p" class="list" category="opinions" />
</txp:if_category>

What this does…
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.

Styles could go this way:

p.list
{
	font-family: Verdana, "Lucida Grande", Tahoma, Helvetica;
	font-size: 11px;
        color:#333;
	margin-left: 10px;
	border-left: 3px solid #ccc;
}
p.list a
{       
        color:#333;
        margin-left:15px;
}
p.list a:hover
{
        border-bottom: 1px dashed #333;
}

Other tags used: category_list, recent_articles