I currently have entries from a section output simply using a variable like:

{% set beer = craft.entries.section('beverages') %}

All of the beer entries have brands assigned to them using the category field. How can I display the beer entries by brand? I use that beer variable throughout my templates for entry counts, filters, etc. I'd like to try and keep that in tact if possible.

I tried to use this but it seems to do more than what I need: http://craftcookbook.net/recipes/330. I also tried the groupBy plugin but had no success in getting that to output anything.

  • Is there only one category per entry, and if not, do you want to list the entry under each category assigned?
    – carlcs
    Commented Nov 26, 2015 at 7:02

1 Answer 1


After some further research this http://craftcookbook.net/recipes/279 was a better fit for my needs. The code I ended up using based on the link is below.

{% set beer = [] %}
{% set beerBrands = craft.categories.group('brandCategory').level(1).find() %}
    {% for category in beerBrands %}
         {% set beerRelatedCategories = craft.entries.section('beers').relatedTo(category).find() %}
         {% set beer = beer|merge(beerRelatedCategories) %}
    {% endfor %}

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.