<p>When you set up your category, you check the <strong>Categories in this group have their own URLs</strong> box, and you give the category a URL (suppose it is <code>category/{slug}</code>), and a template (suppose it is <code>category/_entry</code>). Now in the <code>category/_entry.html</code> template, <code>category</code> will be defined (the way <code>entry</code> is defined on the template for a section entry).</p>

<p><a href="http://buildwithcraft.com/help/entries-related-to-category" rel="nofollow">How do I list the entries related to a category?</a> (tucked away in the Get Help section of the Craft website) describes how to fetch and list the entries related to a category:</p>

<pre><code>{# Fetch all of the entries related to this category #}
{% set entries = craft.entries.relatedTo(category) %}

{# Output them #}
{% for entry in entries %}
    &lt;a href="{{ entry.url }}"&gt;{{ entry.title }}&lt;/a&gt;
{% endfor %}
</code></pre>

<p>If you want to narrow the entries down to a single section, then fetch them like this:</p>

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

CC BY-SA 3.0
2014-08-12T05:57:05.990Z
2014-08-12T05:57:05.990Z
Marion Newlevant
<p>Been trying for days to figure this one out. How do I extract entries from a channel and display only entries related to a category? How do I pull in the related photo? I have this code below but it pulls in all the photos. I don't think I'm doing doing this right.</p>

<pre><code>{% set category = craft.categories.slug('spring-summer').first() %}

{% for post in craft.entries.section('product').relatedTo({targetElement: category}) %}

    &lt;h2&gt;{{ post.title }}&lt;/h2&gt;
    &lt;p&gt;{{ post.price }}&lt;/p&gt;

    {% for product in craft.entries.find() %}
        {% for image in product.photo %}
            &lt;img src="{{ image.getUrl('bottom') }}" /&gt;
        {% endfor %}
    {% endfor %}
{% endfor %}
</code></pre>

<categories>
Related category on a single page
# Related category on a single page

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

Been trying for days to figure this one out. How do I extract entries from a channel and display only entries related to a category? How do I pull in the related photo? I have this code below but it pulls in all the photos. I don't think I'm doing doing this right.
{% set category = craft.categories.slug('spring-summer').first() %}

{% for post in craft.entries.section('product').relatedTo({targetElement: category}) %}

    {{ post.title }}
    {{ post.price }}

    {% for product in craft.entries.find() %}
        {% for image in product.photo %}
            
        {% endfor %}
    {% endfor %}
{% endfor %}

**Tags:** categories


---

## 1 answers

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

When you set up your category, you check the Categories in this group have their own URLs box, and you give the category a URL (suppose it is category/{slug}), and a template (suppose it is category/_entry). Now in the category/_entry.html template, category will be defined (the way entry is defined on the template for a section entry).
How do I list the entries related to a category? (tucked away in the Get Help section of the Craft website) describes how to fetch and list the entries related to a category:
{# Fetch all of the entries related to this category #}
{% set entries = craft.entries.relatedTo(category) %}

{# Output them #}
{% for entry in entries %}
    {{ entry.title }}
{% endfor %}

If you want to narrow the entries down to a single section, then fetch them like this:
{% set entries = craft.entries.section('mySectionHandle').relatedTo(category) %}


---

