<p>Here's another good example for working with categories that may be useful to you. This will loop through all categories (that have entries) and show their entries:</p>

<pre><code>{% set entries = craft.entries.section('someSection').limit(null) %}

{% for category in craft.categories.group('someCategoryGroup').relatedTo(entries) %}
    &lt;h2&gt;{{ category }}&lt;/h2&gt;

    {% for entry in entries.relatedTo(category) %}
        {{ entry.title }}
    {% endfor %}

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

CC BY-SA 3.0
2014-07-05T01:21:54.803Z
2014-07-05T01:21:54.803Z
Simon Kuran
<p>This example assumes you have your <a href="http://buildwithcraft.com/docs/categories#category-groups" rel="nofollow">Category Group</a> setup to use custom URLs.  In the template used to display your categories, the <code>category</code> variable will be available and represent your <a href="http://buildwithcraft.com/docs/templating/categorymodel" rel="nofollow">CategoryModel</a> for that page.</p>

<p>The key is to pass the <code>CategoryModel</code> (in our example below <code>category</code>) to the <code>relatedTo</code> parameter of the Entries tag.</p>

<pre><code>{{ category.title }}

{% paginate craft.entries
    .section('articles')
    .relatedTo(category)
    .limit(10) 
    as entries 
%}

    {% if entries|length %}

        {# Content #}
        {% for entry in entries %}
            {{ entry.title }}
        {% endfor %}

        {# Pagination #}

    {% else %}

        &lt;p&gt;No items have been added to this Category yet.&lt;/p&gt;

    {% endif %}

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

CC BY-SA 3.0
2014-07-05T09:57:24.333Z
Thanks Ben, this has allowed me to loop through all the entries in my channel (only have 1 as I'm using the personal version), I think I am missing something, maybe in the setup of my category group. I'll go back to it and have a root around, many thanks.
bobbyballbags
CC BY-SA 3.0
2014-07-04T22:25:08.573Z
2014-08-04T05:02:47.890Z
2014-08-04T05:02:47.890Z
Ben Parizek
<p>I have a category set up and have added entries to it. How do I loop through these entries, and output just the title of each entry?</p>

<p>Serious noob here but trying to learn, any help would be gratefully received.</p>

<templating><categories><loop>
How can I create a simple loop through entries in a category?
# How can I create a simple loop through entries in a category?

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

I have a category set up and have added entries to it. How do I loop through these entries, and output just the title of each entry?

Serious noob here but trying to learn, any help would be gratefully received.

**Tags:** templating, categories, loop

---

## 2 answers

### Answer by username_2 on 2014-07-04. Score: 6 | Accepted answer

This example assumes you have your Category Group setup to use custom URLs.  In the template used to display your categories, the category variable will be available and represent your CategoryModel for that page.
The key is to pass the CategoryModel (in our example below category) to the relatedTo parameter of the Entries tag.
{{ category.title }}

{% paginate craft.entries
    .section('articles')
    .relatedTo(category)
    .limit(10) 
    as entries 
%}

    {% if entries|length %}

        {# Content #}
        {% for entry in entries %}
            {{ entry.title }}
        {% endfor %}

        {# Pagination #}

    {% else %}

        No items have been added to this Category yet.

    {% endif %}

{% endpaginate %}

> **Comments:**
> **username_0**: Thanks Ben, this has allowed me to loop through all the entries in my channel (only have 1 as I'm using the personal version), I think I am missing something, maybe in the setup of my category group. I'll go back to it and have a root around, many thanks.  

---

### Answer by username_1 on 2014-07-05. Score: 6

Here's another good example for working with categories that may be useful to you. This will loop through all categories (that have entries) and show their entries:
{% set entries = craft.entries.section('someSection').limit(null) %}

{% for category in craft.categories.group('someCategoryGroup').relatedTo(entries) %}
    {{ category }}

    {% for entry in entries.relatedTo(category) %}
        {{ entry.title }}
    {% endfor %}

{% endfor %}


---

