Group posts by year

11 May 2016  

Here is the code template I am using to make a chronological archive1.

{% for post in site.categories.[page.category] %}
{% capture year %}{{ post.date | date: '%Y' }}{% endcapture %}
{% capture nyear %}{{ post.next.date | date: '%Y' }}{% endcapture %}

{% if forloop.first %}
<p>{{ year }}</p><ul>
{% elsif year != nyear %}
</ul><p>{{ year }}</p><ul>
{% endif %}

<li><a href="{{site.baseurl}}{{post.url}}">{{ post.title }}</a>
{{ post.date | date: "%-m/%-d/%y" }}</li>
{% endfor %}
</ul>