Sorting categories in Perch templates

The perch:categories tags are used to output categories inside a Perch template:

<perch:categories id="categories" label="Type of product" set="products">
    <perch:before><ul></perch:before>
        <li><perch:category id="catTitle"></li>
    <perch:after></ul></perch:after>
</perch:categories>

By default the output categories are ordered by catTreePosition, which is the order you set in the central Categories page in the Perch control panel. You can use the sort attribute to change the direction of the order or to order by another column. The default is:

<perch:categories id="categories" label="Type of product" set="products" sort="catTreePosition ASC">
</perch:categories>

You can, for instance, sort by the category title:

<perch:categories id="categories" label="Type of product" set="products" sort="catTitle ASC">
</perch:categories>

You can reverse the direction by using DESC:

<perch:categories id="categories" label="Type of product" set="products" sort="catTitle DESC">
</perch:categories>

Note that you cannot sort by custom fields.

link

Related articles