1

I've got a list of entries grouped by year which is working correctly except that the months are being output in the the reverse order.

This code outputs the years in the correct order but the months in reverse order:

    {# all entries sorted by year/month #}
     {% set allEntries = craft.entries.section('photoblog').limit(null).order('postDate desc') %}

  {% for year, entriesInYear in allEntries | group("postDate.year") %}
      <div class="col-sm-3 col-xs-6" data-mh="years">
        <h3>{{ year }}</h3>
        <ul class="list-unstyled">
        {% for month, entries in entriesInYear | group("postDate|date('F')" ) %}
            <li><a href="/calendar/{{ year }}/{{ month|date('m') }}">{{ month }}&nbsp;({{ entries|length }})</a></li>
        {% endfor %}
        </ul>
      </div>
  {% endfor %}

If I change the '''.order('postDate desc') to asc then the months are in the correct order but the years are reversed. is there a way to get it so that the years are descending but the months are ascending?

screenshot of current code results

enter image description here

1 Answer 1

3

Add the reverse filter to your inner array of entries in month.
http://twig.sensiolabs.org/doc/filters/reverse.html

Your Answer

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

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