1

I'm trying to figure out how I can print the month name i.e April in the below. Currently, it's printing the last three months that contain entries.

{% set year = craft.request.segment(4) %}
{% set month = craft.request.segment(5) %}

{% set entriesInYear = craft.entries.section('bulletinOnline').limit(null).after(year).before(year+1) %}
{% set groupedEntries =  entriesInYear | group("postDate|date('m')") %}

{% for year, entriesInYear in allEntries | group("postDate.year") %}
    {% set counter = ( counter | default(0) ) + 1 %}

    {% for month, entries in entriesInYear | group("postDate|date('m')") %}

        <a href="{{ url('/archive/')}}/{{ year }}/{{ month }}">
            {% for monthWord, entries in entriesInYear|group("postDate|date('F')") %}
                {{ monthWord }}
            {% endfor %}
            &nbsp;({{ entries|length }})
        </a>
    {% endfor %}
{% endfor %}

Example output:

<a href="'/archive/2019/04/">MarchAprilMay(2)</a>
1

Try this:

{% set year = craft.request.segment(4) %}
{% set month = craft.request.segment(5) %}

{% set entriesInYear = craft.entries.section('bulletinOnline').limit(null).after(year).before(year+1) %}
{% set groupedEntries =  entriesInYear | group("postDate|date('m')") %}

{% for year, entriesInYear in allEntries | group("postDate.year") %}
    {% for month, entries in entriesInYear | group("postDate|date('m')") %}

        <a href="{{ url('/archive/')}}/{{ year }}/{{ month }}">
        {{ month |date((year + 1) ~ '-' ~ month ~ '-01')|date('M') }}&nbsp;({{ entries|length }})</a>
    {% endfor %}
{% endfor %}

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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