<p>You can use .relatedTo(category)</p>

<pre><code>{% for category in craft.categories.group('categoryName') %}
  &lt;h2&gt;{{category.title}}&lt;/h2&gt;
  {% for entry in craft.entries.section('news').relatedTo(category) %}
    &lt;a href="{{entry.url}}"&gt;{{entry.title}}&lt;/a&gt;&lt;br&gt;
  {% endfor %}
{% endfor %}
</code></pre>

<p>You can check for length if you don't want to show categories which aren't related to any entry.</p>

<p><a href="https://craftcms.com/docs/relations#the-relatedTo-param//" rel="noreferrer">See the relations documentation</a></p>

CC BY-SA 3.0
2016-04-05T09:10:30.590Z
2016-04-05T09:16:40.420Z
2016-04-05T09:16:40.420Z
Marco Schuler
<p>I would like to know how I can create a page that contains all entries from a section e.g. 'news'. I want to divide the entries by their given category. </p>

<p>News (section)</p>

<p>Category 1:</p>

<ul>
<li>entry in category 1</li>
<li>second entry in category 1</li>
<li>third entry in category 1</li>
</ul>

<p>Category 2:</p>

<ul>
<li>entry in category 2</li>
<li>second entry in category 2</li>
<li>third entry in category 2</li>
</ul>

<p>etc. </p>

<p>Does anyone know the code for this? The categories are all in the same category group. </p>

<entries><categories><filter><category>
Display entries by category (multiple categories)
# Display entries by category (multiple categories)

(Asked by: username_0 on 2016-04-05)

I would like to know how I can create a page that contains all entries from a section e.g. 'news'. I want to divide the entries by their given category.

News (section)

Category 1:

* entry in category 1
* second entry in category 1
* third entry in category 1

Category 2:

* entry in category 2
* second entry in category 2
* third entry in category 2

etc.

Does anyone know the code for this? The categories are all in the same category group.

**Tags:** entries, categories, filter, category

---

## 1 answers

### Answer by username_1 on 2016-04-05. Score: 6

You can use .relatedTo(category)
{% for category in craft.categories.group('categoryName') %}
  {{category.title}}
  {% for entry in craft.entries.section('news').relatedTo(category) %}
    {{entry.title}}
  {% endfor %}
{% endfor %}

You can check for length if you don't want to show categories which aren't related to any entry.
See the relations documentation


---

