<p>You need to loop over the sections. In each section, you then loop over the categories, and display your entries inside them. Something like this.</p>

<pre><code>{% set categories = craft.categories.group('groupHandle').find() %}
{% for section in craft.sections.getAllSections() %}
    {% if section.type == 'channel' %}
        &lt;h1&gt;{{ section.name }}&lt;/h1&gt;
        {% for category in categories %}
            &lt;h2&gt;{{ category.title }}&lt;/h2&gt;
            {% for entry in craft.entries.section(section).relatedTo(category).limit(3).find() %}
                &lt;a href="{{ entry.url }}"&gt;{{ entry.title }}&lt;/a&gt;
            {% endfor %}
        {% endfor %}
    {% endif %}
{% endfor %}
</code></pre>

<p>This is a pretty quick and dirty example. I pull the categories ahead of time so I can reduce the number of database calls. I suggest using the cache to speed things up.</p>

<p>The <a href="http://buildwithcraft.com/docs/templating/" rel="nofollow">template docs</a> (especially the <a href="http://buildwithcraft.com/docs/templating/elementcriteriamodel" rel="nofollow">ElementCriteriaModel</a>) are handy reading materials.</p>

CC BY-SA 3.0
2014-06-26T15:38:14.337Z
Awesome, thanks Bryan! I'm sure the docs will make more sense once I've used Craft a bit more - they seem to make sense but then I struggle to 'join the dots' as it were. Concrete examples like you just gave help me a bit more than the abstracted docs I think - at least until I wrap my head around what's going on more :) Thanks again!
Matt Wilcox
CC BY-SA 3.0
2014-06-26T15:34:28.443Z
2014-06-26T15:34:28.443Z
Bryan Redeagle
<p>I'm trying to create a condensed overview of my website content on my homepage. I'd like that page to loop through all sections, in each section looping through the categories that apply to the section, and for each category to pull the title, uri, and excerpt of the newest three entries.</p>

<p>I'm having trouble wrapping my head around how I'd do that.</p>

<p>What I'm after might be seen as:</p>

<pre>
SECTION
  CATEGORY 1 [title, description, view category archive]
    POST 1 [title, excerpt, publication date, view entry]
    POST 2 [title, excerpt, publication date, view entry]
    POST 3 [title, excerpt, publication date, view entry]
  CATEGORY 2 [title, description, view category archive]
    POST 1 [title, excerpt, publication date, view entry]
    POST 2 [title, excerpt, publication date, view entry]
    POST 3 [title, excerpt, publication date, view entry]
SECTION 2
  CATEGORY 1 [title, description, view category archive]
    POST 1 [title, excerpt, publication date, view entry]
    POST 2 [title, excerpt, publication date, view entry]
    POST 3 [title, excerpt, publication date, view entry]</pre>

<p>For the sake of simplicity, all my categories are currently under a 'global' group. They also map pretty much 1:1 to the EntryTypes available in each section. (I'm not entirely convinced I'm using Categories / EntryTypes correctly, given that 1:1 relation... in fact that's another question to ask).</p>

CC BY-SA 3.0
2014-06-26T15:21:56.547Z
Am I correct that you only want channel sections?
Bryan Redeagle
CC BY-SA 3.0
2014-06-26T15:28:02.193Z
Yes that's right; no point looping through Singles and I don't have any Structures yet.
Matt Wilcox
<categories><sections>
How to list the latest 3 entries per category per section?
# How to list the latest 3 entries per category per section?

(Asked by: username_0 on 2014-06-26)

I'm trying to create a condensed overview of my website content on my homepage. I'd like that page to loop through all sections, in each section looping through the categories that apply to the section, and for each category to pull the title, uri, and excerpt of the newest three entries.
I'm having trouble wrapping my head around how I'd do that.
What I'm after might be seen as:

SECTION
  CATEGORY 1 [title, description, view category archive]
    POST 1 [title, excerpt, publication date, view entry]
    POST 2 [title, excerpt, publication date, view entry]
    POST 3 [title, excerpt, publication date, view entry]
  CATEGORY 2 [title, description, view category archive]
    POST 1 [title, excerpt, publication date, view entry]
    POST 2 [title, excerpt, publication date, view entry]
    POST 3 [title, excerpt, publication date, view entry]
SECTION 2
  CATEGORY 1 [title, description, view category archive]
    POST 1 [title, excerpt, publication date, view entry]
    POST 2 [title, excerpt, publication date, view entry]
    POST 3 [title, excerpt, publication date, view entry]
For the sake of simplicity, all my categories are currently under a 'global' group. They also map pretty much 1:1 to the EntryTypes available in each section. (I'm not entirely convinced I'm using Categories / EntryTypes correctly, given that 1:1 relation... in fact that's another question to ask).

**Tags:** categories, sections
> **Comments:**
> **username_1**: Am I correct that you only want channel sections?  
> **username_0**: Yes that's right; no point looping through Singles and I don't have any Structures yet.  

---

## 1 answers

### Answer by username_1 on 2014-06-26. Score: 4 | Accepted answer

You need to loop over the sections. In each section, you then loop over the categories, and display your entries inside them. Something like this.
{% set categories = craft.categories.group('groupHandle').find() %}
{% for section in craft.sections.getAllSections() %}
    {% if section.type == 'channel' %}
        {{ section.name }}
        {% for category in categories %}
            {{ category.title }}
            {% for entry in craft.entries.section(section).relatedTo(category).limit(3).find() %}
                {{ entry.title }}
            {% endfor %}
        {% endfor %}
    {% endif %}
{% endfor %}

This is a pretty quick and dirty example. I pull the categories ahead of time so I can reduce the number of database calls. I suggest using the cache to speed things up.
The template docs (especially the ElementCriteriaModel) are handy reading materials.

> **Comments:**
> **username_0**: Awesome, thanks Bryan! I'm sure the docs will make more sense once I've used Craft a bit more - they seem to make sense but then I struggle to 'join the dots' as it were. Concrete examples like you just gave help me a bit more than the abstracted docs I think - at least until I wrap my head around what's going on more :) Thanks again!  

---

