2

Using this handy thing (http://buildwithcraft.com/help/entry-archive) to create an archive page, but not quite doing what I need it to do.

Set up as a route to call /year/month, replacing year with current year if not provided and replacing month with most recent month that has posts in it if not provided.

This version will print out all posts from a single year:

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

{% for entry in entriesInYear %}
    <p>{{ entry.title }}</p>
{% endfor %}

And this version will print out the entire year into groups based on month:

{% for month, entries in entriesInYear | group("postDate|date('F')") %}
    <h2>{{ month }}</h2>
    <ul>
        {% for entry in entries %}
            <li>{{ entry.getLink() }}</li>
        {% endfor %}
    </ul>
{% endfor %}

But what I need is to only get the posts from the month in the url and am not sure how to get there... basically an entriesInMonth variable as opposed to an entriesInYear.

3

There's probably a cleaner way to go about this, but something like this should work:

{# These are probably coming from the querystring, but I'll hard code them here #}
{% set year = 2015 %}
{% set month = 'July' %}

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

<h2>{{ month }}</h2>
<ul>
    {% for entry in groupedEntries[month] %}
        <li>{{ entry.getLink() }}</li>
    {% endfor %}
</ul>

You'll probably want to add error checking and validation in case no entries exist for the month or the month/year is invalid, etc.

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.