Displaying list of categories in Textpattern

in textpattern

If you have your entries archived by category, and you want to display all categoy title in your webpage e.g. sidebar, you can do it easily. The key syntax is <txp:category_list />. You can add some attributes in inside this syntax:

  • label="label text" — Label for the top of the list. Default is unset.
  • labeltag="labeltag text" — Independent wraptag for label for the top of the list. Default is unset.
  • break="html tag" — HTML tag to be used for line breaks, without brackets. Default is br.
  • wraptag="html tag" — HTML tag to wrap the returned list with. Default is unset.
  • type="category type" — Available values: article, image, link, file. Default is article.
  • parent="category name" — Will return the Parent category and its dependent categories.
  • class="class name" — CSS class attribute for wraptag, default is category_list.

Sample codes:

Display list of categories, category name linked to category archive page, and using this output:

<ul>
<li><a href="link-to-archive">Category name</a></li>
<li><a href="link-to-archive">Category name</a></li>
<li><a href="link-to-archive">Category name</a></li>
</ul>

In your template, you can use this syntax: <txp:category_list break="li" wraptag="ul" />

If you're new here, you may want to subscribe to my RSS feed go get the latest entry from your RSS reader. You can also have my contents delivered to your inbox.