Textpattern CMS Template Tags

<txp:category_list /> sing/cont tag, 10 attributes

category_list

The category_list tag can be used as either a single tag or container tag which is used to produce a list of linked categories.

Related: if_category, if_first_category, if_last_category

attributes

parent="unset" 
  • Return only specified category and its “children” categories.
categories="unset" 
  • Comma-separated list of categories to include, displayed in the order specified (unless overridden by sort attribute). Use category names not Titles here — note that TXP automatically converts the names to lower case and converts spaces to hyphens when they are created
exclude="unset" 
  • List of category names which will be excluded from the list. categories takes precedence over exclude.
type="article" 
  • Available values: article, image, link, file.
children="1" (boolean) 
  • Can limit the list depth to one level below the parent category.
  • Values: 0 (no children, i.e. only show one level below the parent) or 1 (all nested categories).
sort="name asc" 
  • Values
    • id
    • name
    • type
    • parent
    • title
    • rand() (random)
  • Direction
    • asc (ascending)
    • desc (descending)
form="form name" 
  • Use the specified form to process each included category.
section="unset" 
  • Link to specified section.
this_section="0" (boolean) 
  • Link to currently active section (overrides section attribute).
active_class="unset" 
  • (X)HTML class attribute to be applied to the “active” or current link in a list (only works in the single tag without the form attribute).

presentation

label="unset" 
  • Label prepended to item (or as first list item, where appropriate).
  • if wraptag is available and is set to ol or ul, the label will be the first list item.
labeltag="unset" 
  • (X)HTML tag (without brackets) to wrap around label.
break="br" 
  • (X)HTML tag (without brackets) or string to separate list items.
wraptag="unset" 
  • (X)HTML tag (without brackets) to wrap around the list.
class="category_list" 
  • (X)HTML class attribute to apply to the wraptag.

genealogy

Version 4.0.7

  • Can be used as a container tag.
  • form and children attributes added.

Version 4.0.4

  • active_class, categories, exclude, section, this_section added.
<txp:category_list /> 3 examples

Labeled category list

<txp:category_list label="Categories" wraptag="p" break="br" />

As an unordered list

<txp:category_list break="li" wraptag="ul" />

Styles could go this way

.category_list {
     list-style-type:none;
}

Set active class using the container tag

This code will add class=“active” to the <li> element around the “current” category in the list.

<txp:category_list wraptag="ul" break="">
<li<txp:if_category name='<txp:category />'> class="active"</txp:if_category>>
<txp:category title="1" link="1" />
</li>
</txp:category_list>