I have two channel sections, each with only their own entry types. I've added the same category group field to both. I'd like to filter each channel's list of entries by the same category group.

So if you're on Channel Steve (for example) you could hit the Category B link and see all the entries in the channel tagged with Category B. Then the same for Channel Bob. The same Category B link would be there, but when clicked it would show only the entries in Channel Bob tagged with Category B.

The problem I'm running into is that each category group uses only one path and template, and I need n of them. It seems like it'd be easy enough to associate one path/categories with one template multiple times for each category group so the category variable would be available on each channel's template. I think this is the optimal solution.

Right now I'm making it work with URL segment sniffing, but that feels hacky.

So, how can you set up category filtering on multiple channels with the same category group?

1 Answer 1


I would use a dynamic route instead of the path and template assigned in the category group. If you want the urls to be /Steve/B and /Bob/B, the route would look like {tag}/{slug}. Then in the template, fetch the channel using tag, and the category handle using slug.

Fetching the category:

{% set category = craft.categories.group('categoryGroup').slug(slug).first %}
{% if not category %}{% exit 404 %}{% endif %}

Fetching the entries:

{% set myEntries = craft.entries.section(tag).relatedTo(category) %}
  • What's the command to load the category object with the slug?
    – ponies
    Feb 17, 2017 at 16:43
  • @ponies - added to the answer Feb 17, 2017 at 17:02

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.