<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>

CC BY-SA 4.0
2018-08-13T19:58:25.103Z
2018-08-13T19:58:25.103Z
Robin Schambach
<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>

<loop>
Batch entries by year?
# 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 filter
{% set allEntries = craft.entries.section('blog').all() %}

{% set allEntriesByYear = allEntries|group('postDate.year') %}

{% for year, entriesInYear in allEntriesByYear %}
    {{ year }}

    
        {% for entry in entriesInYear %}
            {{ entry.title }}
        {% endfor %}
    
{% endfor %}


---

