Textpattern tips, tutorials and code snippets

Category list showing number of articles

Textpattern features a very useful category list tag which covers most use, except for those instances where you would like to display the number of articles in each category.

For this purpose, we need the cbs_category_list plugin, which differs from the in-built TXP category_list tag in that it is section-sensitive, and only list article categories.

In addition, the plugin only outputs a category if an article is found in the section.

  1. Download the cbs_category_list plugin, install, activate.

Create your sidebar form

<h2>TXP Tips categories</h2>
<txp:cbs_category_list section="articles" wraptag="ul" break="li" showcount="true" class="category_list" activeclass="active" />

I use the above code for this site. The code is placed in a form called sidebar, type misc. The attribute showcount="true" is what we need to display the number of articles in a given category.

Thanks to Craig Valadez for requesting this example.

Use Textile help to style your comments