1

I'm creating a monthly archive page (for a specified year) for a section.

Standard code to output the months and entries as follows:

{% set entriesInYear = craft.entries.section('blog').limit(null).after(year).before(year+1) %}

{% for month, entries in entriesInYear | group("postDate|date('F')") %}
    <div class="month">
        <h3>{{ month }}</h3>
        <ul>
            {% for entry in entries %}
                <li>{{ entry.getLink() }}</li>
            {% endfor %}
        </ul>
    </div><!-- month -->
{% endfor %}

That's all working perfectly, what I can't figure out is how to reverse the order of the output, so I get January -> December, instead of December -> January.

I'm sure this is simpler than my head is making out, but that will teach me to be coding on a Sunday.

1 Answer 1

1

If you change your query and sort by ascending postdate, it will start with the oldest and end with the newest:

    {% set entriesInYear = craft.entries.section('blog').limit(null).after(year).before(year+1).order('postDate asc') %}
1
  • I never even thought about changing the order of the entries, I was too busy trying to change the order of the month groups. Thanks! Commented Apr 4, 2016 at 15:06

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.