17

I would like to output a list of all the categories in a category group on the front end. How do I do that?

0

1 Answer 1

27

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>
1
  • Set up on craft is through the settings, then category button. Not through category tab.
    – Matteo
    Aug 20, 2015 at 18:00

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.