Is is possible to loop through both a category group and tag group in a for loop?

Categories: blue, red, orange Tags: basketball

Loop displays: basketball, blue, orange, red.

1 Answer 1


Something like this may work for you (untested).

{% set categories = craft.categories.group('myCategoryGroup').find %}
{% set tags = craft.tags.group('myTagGroup').find %}
{% set elements = categories|merge(tags) %}
    {% for element in elements %}
        <li>{{ element.title }}</li>
    {% endfor %}

Sorting them alphabetically is a little more difficult. For that you may want to try twig's sort filter or, failing that, the supersort or craft-twig-better-sort plugins.

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.