# Group by year/time order

**URL:** <https://zola.discourse.group/t/group-by-year-time-order/192>\
**Category:** Feature requests\
**Created:** [September 9, 2019, 3:43pm UTC](https://zola.discourse.group/t/group-by-year-time-order/192 "2019-09-09T15:43:18Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![tcurdt](https://yyz2.discourse-cdn.com/free1/user_avatar/zola.discourse.group/tcurdt/32/93_2.png) [@tcurdt](https://zola.discourse.group/u/tcurdt)\
**Post date:** [September 9, 2019, 3:43pm UTC](https://zola.discourse.group/t/group-by-year-time-order/192/1 "2019-09-09T15:43:18Z")

</div>

When crafting an archive page I wanted to group the posts based on the post date year (without pagination). This is what I tried…

```auto
for year, posts in section.pages | group_by(attribute="year")

```

But I also wanted the year to be in descending order while the posts (per year) be in ascending order.

I didn’t find any way of doing this. Is there one?

---

<div class="post-metadata">

**Author:** ![mysteriouspants](https://yyz2.discourse-cdn.com/free1/user_avatar/zola.discourse.group/mysteriouspants/32/94_2.png) [@mysteriouspants](https://zola.discourse.group/u/mysteriouspants)\
**Post date:** [September 11, 2019, 5:24am UTC](https://zola.discourse.group/t/group-by-year-time-order/192/2 "2019-09-11T05:24:44Z")

</div>

I figured out how to do this, but it’s a little fiddly.

```auto
{% set year = "-1" %}
{% for page in paginator.pages %}
  {% set this_year = page.date | date(format="%Y") %}
  {% if year != this_year %}
    {% set_global year = this_year %}
    <li class="year"><h2>{{ year }}</h2></li>
  {% endif %}
  <li>
    <a href="{{ page.permalink | safe }}"><aside class="dates">{{ page.date | date(format="%b %d") }}</aside></a>
    <a href="{{ page.permalink | safe }}">{{ page.title }}<h2>{{ page.description }}</h2></a>
  </li>
{% endfor %}

```

In a `ul` it will create a header `li` for each grouping.

EDIT: Additionally, for ordering, you can control the order in the `_index.md` file’s frontmatter:

```auto
+++
sort_by = "date"
+++

```

If you want to control the order, you may have to use the Tera `reverse` filter, though I’m not sure if that works in this case.

---

<div class="post-metadata">

**Author:** ![tcurdt](https://yyz2.discourse-cdn.com/free1/user_avatar/zola.discourse.group/tcurdt/32/93_2.png) [@tcurdt](https://zola.discourse.group/u/tcurdt)\
**Post date:** [September 11, 2019, 7:23pm UTC](https://zola.discourse.group/t/group-by-year-time-order/192/3 "2019-09-11T19:23:27Z")

</div>

It feels a bit like a workaround - but I guess that should do it.  
Thanks a lot, @mysteriouspants.
