How to use Textpattern CMS category navigational tags

admin-ajaxContinuing in this series of articles about Textpattern CMS navigational tags, it’s time to learn how to use the collection of tags that relate to categories. There are four in total:

  • `category`
  • `category1`
  • `category2`
  • `category_list`

Although they look similar, their output and usage differs considerably. The `category` tag will output information relating a category view. The next two tags, `category1` and `category2`, will output the respective category or categories assigned to an article. Finally, `category_list` will combine elements of all three preceding tags and produce a list of linked categories. All 4 tags can be used in both single and container instances.

When `category` is used a single tag, it assumes the following defaults of its attributes:

  • class=”CSS class name” (default: unset)
  • link=”boolean” (default: 0)
  • name=”category-name” (default: unset – current category)
  • section=”section-name” (default: unset – current section)
  • this_section=”boolean” (default: 0)
  • title=”boolean” (default: 0)
  • type=”category type” (default: article)
  • url=”boolean” (default: 0)
  • wraptag=”html wrapper” (default: unset)

Sensible defaults, but at the same time there’s a lot to play around with to make some cool code blocks. Some additional notes on the above attributes:

  • If no `wraptag` is supplied and link=”1″, the `class` is applied to the anchor.
  • Both `name` and `section` use the lower-case, hyphenated form of the respective name, regardless of whether `title` is set or not.

Here’s an example of `category` in action. This code block shows the category view title and hyperlinks it:

<txp:category link="1" name="posts" title="1" wraptag="span" />

The `category1` and `category2` tags have identical attributes as one another, and a subset of the `category` attributes despite the marked difference in the their use:

  • class=”CSS class name” (default: unset)
  • link=”boolean” (default: 0)
  • section”section-name” (default: unset – current section)
  • title=”boolean” (default: 0)
  • this_section=”boolean” (default: 0)
  • wraptag=”html wrapper” (default: unset)

Again, straightforward and sensible. Be aware that `link` works in the context of a single tag.

Examples of `category1` and `category2` in use are a little less exciting, but bear with me. Here’s how to output the `category1` title and hyperlink it, ideal if you want to link to other posts in the same category:

<txp:category1 link="1" title="1" />

Lastly, the `category_list` tag is the most flexible in what it can do with its attributes. There are a whole bunch to use:

  • active_class=”CSS class name” (default: unset) (Only works in the single tag without the form attribute. For setting an active class in the container tag see example 3.)
  • categories=”category name(s)” (default: unset – all categories)
  • children=”boolean” (default: 1, show nested categories)
  • exclude=”category name(s)” (default: unset)
  • form=”form name” (default: `default` form)
  • parent=”category name” (default: unset)
  • section=”section name” (default: unset)
  • sort=”sort value(s)” (default: name asc – alphabetical, by name ascending)
  • type=”category type” (default: article)

Here’s how you can roll out `category_list` to output a list of — uh — categories:

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

This will build you an unordered list and break each entry with a list item. Neat, huh? Next time: `link_to_home`, `link_to_prev` and `link_to_next`.

Looking for quality Textpattern Hosting? Look no further than Arvixe Web Hosting and use coupon TEXTPATTERN for 20% off your first invoice!

Tags: , , , , , , , , , | Posted under Textpattern | RSS 2.0

Author Spotlight

Pete Cooper

Pete Cooper has been using Textpattern since 2005. Textpattern is his preferred CMS weapon of choice. Its logical and flexible approach to content management makes Pete happy, as does its lightweight core and helpful user community. Pete's website - - runs on top of Textpattern and chronicles his day-to-day experiences from his home near the Atlantic in north Cornwall, United Kingdom.

Leave a Reply

Your email address will not be published. Required fields are marked *