Answers.Body: <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>
  
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2014-08-12T17:20:22.790Z
Answers.LastActivityDate: 2014-08-12T17:20:22.790Z
Answers.UserDisplayName: Brad Bell
Body: <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>
  
Tags: <entries><categories><relations>
Title: How do I find the category an entry belongs to?
ThreadText: # 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 %}
      <span class="event">{{ entry.title }}</span>
  {% endfor %}
  
  ```
  
  Code so far is above.
  
  The category has a background color field which I want to apply to the `<span>`.
  
  **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
      #}
  
      <span class="event" style="background-color: {{ category.colorFieldHandle }}">{{ entry.title }}</span>
  {% endfor %}
  
  ```
  
  
  ---
  
  