<p>If I'm following you, you've got a category group setup with a color field on its field layout.</p>

<p>Then you've got a category field setup with it's source set to that category group and in an entry, you want to get to the color field on the category group.</p>

<pre><code>{% for entry in entries %}

    {# Grab the first category #}
    {% set category = entry.categoryFieldHandle.first() %}

    {# 
        Or if there are multiple categories...
        set category = entry.categoryFieldHandle.find()
        And loop through to find the one you want
    #}

    &lt;span class="event" style="background-color: {{ category.colorFieldHandle }}"&gt;{{ entry.title }}&lt;/span&gt;
{% endfor %}
</code></pre>

CC BY-SA 3.0
2014-08-12T17:20:22.790Z
2014-08-12T17:20:22.790Z
Brad Bell
<p>I have a channel with entries which have a category field which is required.
When the entries are listed on a page how do I find the category that it belongs to?</p>

<pre><code>{% for entry in entries %}
    &lt;span class="event"&gt;{{ entry.title }}&lt;/span&gt;
{% endfor %}
</code></pre>

<p>Code so far is above. </p>

<p>The category has a background color field which I want to apply to the <code>&lt;span&gt;</code>.</p>

<entries><categories><relations>
How do I find the category an entry belongs to?
# How do I find the category an entry belongs to?

(Asked by: username_0 on 2014-08-12)

I have a channel with entries which have a category field which is required.
When the entries are listed on a page how do I find the category that it belongs to?
{% for entry in entries %}
    {{ entry.title }}
{% endfor %}

Code so far is above. 
The category has a background color field which I want to apply to the .

**Tags:** entries, categories, relations


---

## 1 answers

### Answer by username_1 on 2014-08-12. Score: 3

If I'm following you, you've got a category group setup with a color field on its field layout.
Then you've got a category field setup with it's source set to that category group and in an entry, you want to get to the color field on the category group.
{% for entry in entries %}

    {# Grab the first category #}
    {% set category = entry.categoryFieldHandle.first() %}

    {# 
        Or if there are multiple categories...
        set category = entry.categoryFieldHandle.find()
        And loop through to find the one you want
    #}

    {{ entry.title }}
{% endfor %}


---

