<p>It might be quicker to turn it around: first get all the entries you need, then group those by their category:</p>

<pre><code>{% set entries = craft.entries.section('people').find() %}

{% for category, catEntries in entries | group('categoryFieldHandle.first().title') %}
    &lt;h1&gt;{{ category }}&lt;/h1&gt;
    {% for entry in catEntries %}
        &lt;a href="{{ entry.url }}"&gt;{{ entry.title }}&lt;/a&gt;
    {% endfor %}
{% endfor %}
</code></pre>

CC BY-SA 3.0
2014-09-25T15:19:31.793Z
Ok, just tried that and all it's doing is outputting the section name.
Lighty_46
CC BY-SA 3.0
2014-09-25T15:22:44.880Z
Try putting .find() behind the first rule.
Paul
CC BY-SA 3.0
2014-09-25T15:33:46.360Z
Hmmmm, nope still does the same thing.
Lighty_46
CC BY-SA 3.0
2014-09-25T15:36:07.930Z
Wait, it works now for some reason. I used: {% set entries = craft.entries.find({ section: 'people'}) %} in the end. Thanks for the help!
Lighty_46
CC BY-SA 3.0
2014-09-25T15:55:22.957Z
Strange, I would think that those two things have the same result ..
Paul
CC BY-SA 3.0
2014-09-26T08:56:17.037Z
Maybe there was a white space issue or something? anyway it's working now so thanks!
Lighty_46
CC BY-SA 3.0
2014-09-25T15:14:40.447Z
2014-09-25T17:32:54.220Z
2014-09-25T17:32:54.220Z
Paul
<p>Ok, so basically I want to loop through categories and output the title of each category along with all the associated entries. Like so:</p>

<p><strong>Category 1:</strong> Entry 1 Title, Entry 3 Title</p>

<p><strong>Category 2:</strong> Entry 2 Title, Entry 4 Title</p>

<p>(Where entry 1 and 3 are category 1 - and entry 2 and 4 are category 2)</p>

<p>This was the closest I got:</p>

<pre><code>    {% set categories = craft.categories.group('jobCategories').find() %}

        {% for category in categories %}

            &lt;h1&gt;{{ category.title }}&lt;/h1&gt;

            {% for entry in craft.entries.section('people').relatedTo(category).find() %}

                &lt;a href="{{ entry.url }}"&gt;
                     {{ entry.title }}
                &lt;/a&gt;

            {% endfor %}

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

<p>How would I do this?</p>

<p>Thanks!</p>

<categories>
How do I output entries by their category?
# How do I output entries by their category?

(Asked by: username_0 on 2014-09-25)

Ok, so basically I want to loop through categories and output the title of each category along with all the associated entries. Like so:
Category 1: Entry 1 Title, Entry 3 Title
Category 2: Entry 2 Title, Entry 4 Title
(Where entry 1 and 3 are category 1 - and entry 2 and 4 are category 2)
This was the closest I got:
    {% set categories = craft.categories.group('jobCategories').find() %}

        {% for category in categories %}

            {{ category.title }}

            {% for entry in craft.entries.section('people').relatedTo(category).find() %}

                
                     {{ entry.title }}
                

            {% endfor %}

    {% endfor %}

How would I do this?
Thanks!

**Tags:** categories

---

## 1 answers

### Answer by username_1 on 2014-09-25. Score: 8 | Accepted answer

It might be quicker to turn it around: first get all the entries you need, then group those by their category:
{% set entries = craft.entries.section('people').find() %}

{% for category, catEntries in entries | group('categoryFieldHandle.first().title') %}
    {{ category }}
    {% for entry in catEntries %}
        {{ entry.title }}
    {% endfor %}
{% endfor %}

> **Comments:**
> **username_0**: Ok, just tried that and all it's doing is outputting the section name.  
> **username_1**: Try putting .find() behind the first rule.  
> **username_0**: Hmmmm, nope still does the same thing.  
> **username_0**: Wait, it works now for some reason. I used: {% set entries = craft.entries.find({ section: 'people'}) %} in the end. Thanks for the help!  
> **username_1**: Strange, I would think that those two things have the same result ..  
> **username_0**: Maybe there was a white space issue or something? anyway it's working now so thanks!  

---

