Take the 2-minute tour ×
Craft CMS Stack Exchange is a question and answer site for administrators, end users, developers and designers for Craft CMS. It's 100% free, no registration required.

I have this piece of code which orders my entries by month, which is working great. I only have two issues which I can't work out. How would I display the year of the month beside the month title eg:

<h2>{{ month }} > {{ year }}</h2>

As the list could run over a number of years it would be good to distinguish this. The next part is I can't seem to convert the month from a number ie: 8 to the word ie. "august". When I filter it, it just returns "Jan".

{% set allEntries = craft.entries.section('featureArticles').find() %}
{% set allEntriesByMonth = allEntries|group('postDate.month') %}

{% for month, entriesInMonth in allEntriesByMonth %}

    <h2>{{ month }}</h2>

    <ul>
        {% for entry in entriesInMonth %}
            <li><a href="{{ entry.url }}">{{ entry.title }}</a></li>
        {% endfor %}
    </ul>

{% endfor %}
share|improve this question

1 Answer 1

up vote 3 down vote accepted

You're close!

We've got an example of how to do this here: http://buildwithcraft.com/help/entry-archive#grouping-by-year-and-then-month

The trick is to group by year first, then by month. Using the 'F' token is how to tell PHP to display the name of the month.

share|improve this answer
    
Thanks Brad, this seems like it will do the trick. Can I still use the {{ year }} tag inside the month loop so it gives me August - 2014 as a title? –  Daryl Campbell Aug 10 at 16:43
    
Yup... will still work fine there. If that gets you what you want, mind marking this as the correct answer? –  Brad Bell Aug 10 at 17:17
    
this made my day! thanks a lot! –  outline4 Sep 3 at 9:17

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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