I have a template, /calendar, which outputs a list of all entries from the events channel. If a user clicks a link for "July 2015", I want the same template to load showing only the events for July 2015. I can fetch the entries for a given month with something like this.
{% set setMonth = '2015-07' %}
{% set firstDay, lastDay
=
setMonth ~ '-01',
setMonth ~ '-' ~ setMonth|date('t')
%}
{% set after, before
=
firstDay|date_modify('-1 day')|date('Y-m'),
lastDay|date_modify('+1 day')|date('Y-m')
%}
{% set events = craft.entries.section('events').after(after).before(before)
%}
I want to pass the date that will be assigned to setMonth
in the URL using something like /calendar/2015-07, but I currently get a 404 error.
How can I pass the date in the URL without throwing a 404?
To make it even more complex, this template can also be filtered by category, so there would also be times the URL would look something like /calendar/catslug/2015-07. In this case, the template should display only the July events from the catslug category.
Assuming I can conquer the aforementioned 404 problem, will Craft still recognize /calendar/catslug/2015-07 as a category-triggering URL, or will the addition of the date segment break that functionality?
I suspect this isn't as difficult as I'm making it, so any assistance is appreciated.
Thanks in advance.
/calendar/catslug/2015-07
causes Craft to no longer recognizecatslug
as a category indicator, so any category-based filtering is lost. – Philip Jones Jun 29 '15 at 14:22