I'm sorry If this has been answered before, but I couldn't find any answer that would work for me. Maybe I'm just treating category fields the wrong way and I should be trying to do this with tags.

Basically, I created a category group called colors. I also have several categories like green, blue, red... I assigned URLs that look like mysite/colors/red, mysite/colors/blue.

All of the colors point to the same template colors/index.html

How can I display only the entries in craft.entries.section('news') that are in the "red" color category when I visit mysite/colors/red?

Thanks in advance.

1 Answer 1


You want to use the relatedTo filter. See the docs here: https://craftcms.com/support/entries-related-to-category where category is your last URL segment (eg red).

Just a quick addition... if your category URL for the category group matches what you've used above mysite/colors/red and you are using the category template for that group then you will have a category variable already to use in the relatedTo filter.

  • That worked. I guess I was overthinking it. Thanks Mike Commented Jul 18, 2017 at 12:25

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.