Answers.Body: <p>You can use the <a href="https://docs.craftcms.com/v2/templating/filters.html#group" rel="nofollow noreferrer">group</a> filter</p>
  
  <pre class="lang-twig prettyprint-override"><code>{% set allEntries = craft.entries.section('blog').all() %}
  
  {% set allEntriesByYear = allEntries|group('postDate.year') %}
  
  {% for year, entriesInYear in allEntriesByYear %}
      &lt;h2&gt;{{ year }}&lt;/h2&gt;
  
      &lt;ul&gt;
          {% for entry in entriesInYear %}
              &lt;li&gt;&lt;a href="{{ entry.url }}"&gt;{{ entry.title }}&lt;/a&gt;&lt;/li&gt;
          {% endfor %}
      &lt;/ul&gt;
  {% endfor %}
  </code></pre>
  
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2018-08-13T19:58:25.103Z
Answers.LastActivityDate: 2018-08-13T19:58:25.103Z
Answers.UserDisplayName: Robin Schambach
Body: <p>I have a press release index page that loops through all the press releases. I want to organize them by year. So everything in 2018 will have a header that says 2018 press releases and then all the press releases for 2018 and so on.</p>
  
  <p>Should I do a conditional that checks the date, or is there something like the | batch but for date? Open to ideas. </p>
  
Tags: <loop>
Title: Batch entries by year?
ThreadText: # Batch entries by year?
  
  (Asked by: username_0 on 2018-08-13)
  
  I have a press release index page that loops through all the press releases. I want to organize them by year. So everything in 2018 will have a header that says 2018 press releases and then all the press releases for 2018 and so on.
  
  Should I do a conditional that checks the date, or is there something like the | batch but for date? Open to ideas.
  
  **Tags:** loop
  
  
  ---
  
  ## 1 answers
  
  ### Answer by username_1 on 2018-08-13. Score: 1 | Accepted answer
  
  You can use the [group](https://docs.craftcms.com/v2/templating/filters.html#group) filter
  
  ```twig
  {% set allEntries = craft.entries.section('blog').all() %}
  
  {% set allEntriesByYear = allEntries|group('postDate.year') %}
  
  {% for year, entriesInYear in allEntriesByYear %}
      <h2>{{ year }}</h2>
  
      <ul>
          {% for entry in entriesInYear %}
              <li><a href="{{ entry.url }}">{{ entry.title }}</a></li>
          {% endfor %}
      </ul>
  {% endfor %}
  
  ```
  
  
  ---
  
  