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.


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.

| improve this answer | |

Your Answer

