<p>You want to use the <code>relatedTo</code> filter. See the docs here: <a href="https://craftcms.com/support/entries-related-to-category" rel="nofollow noreferrer">https://craftcms.com/support/entries-related-to-category</a> where <code>category</code> is your last URL segment (eg red).</p>

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

CC BY-SA 3.0
2017-07-18T12:25:34.150Z
That worked. I guess I was overthinking it. Thanks Mike
Ricardo Henriquez
CC BY-SA 3.0
2017-07-18T02:40:42.223Z
2017-07-18T02:46:08.903Z
2017-07-18T02:46:08.903Z
Mike
<p>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.</p>

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

<p>All of the colors point to the same template <code>colors/index.html</code></p>

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

<p>Thanks in advance.</p>

<templating><categories>
Display entries related to Category Field
# Display entries related to Category Field

(Asked by: username_0 on 2017-07-18)

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.

**Tags:** templating, categories


---

## 1 answers

### Answer by username_1 on 2017-07-18. Score: 3 | Accepted answer

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.

> **Comments:**
> **username_0**: That worked. I guess I was overthinking it. Thanks username_1  

---

