I would like to output a list of all the categories in a category group on the front end. How do I do that?
1 Answer
You can fetch your categories on the front end using craft.categories, which has a group param that can be used to filter categories by a given group handle.
{% set categories = craft.categories.group('myGroupHandle') %}
If the category group is limited to a single level, you can loop through those using a basic for-loop:
<ul>
{% for category in categories %}
<li>{{ category.title }}</li>
{% endfor %}
</ul>
If the category group can be multi-level, you might be better off using the {% nav %} tag instead:
<ul>
{% nav category in categories %}
<li>
{{ category.title }}
{# Output a nested <ul> if this category has any children #}
{% ifchildren %}
<ul>{% children %}</ul>
{% endifchildren %}
</li>
{% endnav %}
</ul>
-
Set up on craft is through the settings, then category button. Not through category tab.– MatteoCommented Aug 20, 2015 at 18:00