<p>I would use a <a href="https://craftcms.com/docs/routing#dynamic-routes" rel="nofollow noreferrer">dynamic route</a> instead of the path and template assigned in the category group. If you want the urls to be <code>/Steve/B</code> and <code>/Bob/B</code>, the route would look like <code>{tag}/{slug}</code>. Then in the template, fetch the channel using <code>tag</code>, and the category handle using <code>slug</code>.</p>

<p>Fetching the category:</p>

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

<p>Fetching the entries:</p>

<pre><code>{% set myEntries = craft.entries.section(tag).relatedTo(category) %}
</code></pre>

CC BY-SA 3.0
2017-02-17T16:43:05.023Z
What's the command to load the category object with the slug?
ponies
CC BY-SA 3.0
2017-02-17T17:02:56.897Z
@ponies - added to the answer
Marion Newlevant
CC BY-SA 3.0
2017-02-16T23:35:19.913Z
2017-02-17T17:02:37.773Z
2017-02-17T17:02:37.773Z
Marion Newlevant
<p>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.</p>

<p>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.</p>

<p>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.</p>

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

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

<categories><sections><navigation><filter><channels>
How to use the same category group as a filter on multiple channel sections?
# How to use the same category group as a filter on multiple channel sections?

(Asked by: username_0 on 2017-02-15)

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?

**Tags:** categories, sections, navigation, filter, channels


---

## 1 answers

### Answer by username_1 on 2017-02-16. Score: 2 | Accepted answer

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) %}

> **Comments:**
> **username_0**: What's the command to load the category object with the slug?  
> **username_1**: @username_0 - added to the answer  

---

