Answers.Body: <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>
  
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2016-04-05T09:10:30.590Z
Answers.LastActivityDate: 2016-04-05T09:16:40.420Z
Answers.LastEditDate: 2016-04-05T09:16:40.420Z
Answers.UserDisplayName: Marco Schuler
Body: <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>
  
Tags: <entries><categories><filter><category>
Title: Display entries by category (multiple categories)
ThreadText: # 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') %}
    <h2>{{category.title}}</h2>
    {% for entry in craft.entries.section('news').relatedTo(category) %}
      <a href="{{entry.url}}">{{entry.title}}</a><br>
    {% 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](https://craftcms.com/docs/relations#the-relatedTo-param//)
  
  
  ---
  
  