<p><a href="http://buildwithcraft.com/help/entries-related-to-category" rel="nofollow">How do I list the entries related to a category?</a> article on the Craft site should get you headed in the right direction.</p>

<blockquote>
  <p>You can fetch the entries related to a given category with a little
  help from <a href="http://buildwithcraft.com/docs/templating/craft.entries" rel="nofollow">craft.entries</a> and the <a href="http://buildwithcraft.com/docs/relations#the-relatedTo-param" rel="nofollow">relatedTo</a> param.</p>
</blockquote>

<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>

CC BY-SA 3.0
2014-07-19T01:39:51.060Z
2014-07-21T17:34:55.393Z
2014-07-21T17:34:55.393Z
Marion Newlevant
<p>I'm really struggling to display entries of a category, based on the segment. In other words, I have 1 category template, so the category needs to be determined dynamically (*we still  do this by segment, right?? or is that not the best practice?)</p>

<p>I was trying something like this, but I can't seem to get it right:</p>

<pre><code>{% for category in craft.categories.group('typeOfPack').find() %}
     {% set active = (
        craft.request.Segment(2) == category.slug
     ) %}

    {% for entry in entry.typeOfPack.search('active').find()  %}
        &lt;h3&gt;{{ entry.title }}&lt;/h3&gt;
    {% endfor %}


{% endfor %}
</code></pre>

<p>Apologies if this offensively bad. As I try to get my head around Twig, I'm wondering if there are some high level errors, for instance: 
1. Does the {% for entry... %} need to be inside the {%for category... %}? Do I even need to do the {% for category...%} stuff if I'm just needing entries, or is the ".search(...)" sufficient? </p>

<p>Thank you so much.</p>

<p>Big Mike</p>

<categories>
Display category entries based on Segment?
# Display category entries based on Segment?

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

I'm really struggling to display entries of a category, based on the segment. In other words, I have 1 category template, so the category needs to be determined dynamically (*we still  do this by segment, right?? or is that not the best practice?)
I was trying something like this, but I can't seem to get it right:
{% for category in craft.categories.group('typeOfPack').find() %}
     {% set active = (
        craft.request.Segment(2) == category.slug
     ) %}

    {% for entry in entry.typeOfPack.search('active').find()  %}
        {{ entry.title }}
    {% endfor %}


{% endfor %}

Apologies if this offensively bad. As I try to get my head around Twig, I'm wondering if there are some high level errors, for instance: 
1. Does the {% for entry... %} need to be inside the {%for category... %}? Do I even need to do the {% for category...%} stuff if I'm just needing entries, or is the ".search(...)" sufficient? 
Thank you so much.
username_0

**Tags:** categories


---

## 1 answers

### Answer by username_1 on 2014-07-19. Score: 2

How do I list the entries related to a category? article on the Craft site should get you headed in the right direction.

You can fetch the entries related to a given category with a little
  help from craft.entries and the relatedTo param.

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

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


---

