ExpressionEngine - displaying subcategories

Getting ExpressionEngine to display only subcategories can be tricky without the use of 3rd party addons. Here’s one quick and dirty way using the Category Heading tag with a Query.

{exp:channel:category_heading channel="mychannel"}
{layout:set name="title" value="{category_name} {site_name}"}


{if category_description}
<!-- run the query to fetch subcategory variables -->
{exp:query sql="SELECT 
  FROM exp_categories WHERE parent_id = '{category_id}' ORDER BY cat_order;"}
<a href="{path='template-group/template'}/category/{cat_url_title}">{cat_name}</a>


The clever stuff happens in the query tag’s parent_id field that assigns the ID of the current category being viewed, the output being that categorie’s immediate children.

This won’t work for all occasions, it’ll only display one level deep from the current category, but when all you want is a list of the current categories subcategories this should do the trick for you.

You might also like

You don't know unless you ask

Contact me today