<p>For generating the nav, this should work.</p>

<pre><code>{% set allEntriesByWeek = allEntries|group("postDate|date('Y-W')") %}
{% for week, entry in allEntriesByWeek %}
    &lt;li&gt;&lt;a href="events/{{ week|replace('-','/') }}"&gt;{{ week }}&lt;/a&gt;&lt;/li&gt;
{% endfor %}
</code></pre>

<p>For grabbing entries (using the 'week' and 'year' variables passed via the route).</p>

<pre><code>{% set startDate = now.setISODate(year, week) %}
{% set endDate = startDate|date_modify("+7 days") %}
{% set entries = craft.entries.section('events').postDate('and', '&gt;= ' ~ startDate, '&lt; ' ~ endDate ) %}
{% for entry in entries %}
    {{ entry.title }}
{% endfor %}
</code></pre>

<p>For pagination.</p>

<pre><code>&lt;a href="events/{{ startDate|date_modify('+7 days')|date('Y/W') }}"&gt;Next Week&lt;/a&gt;
&lt;a href="events/{{ startDate|date_modify('-7 days')|date('Y/W') }}"&gt;Previous Week&lt;/a&gt;
</code></pre>

CC BY-SA 3.0
2015-05-01T07:35:04.850Z
Why is it that your weeks are only 6 days long?
carlcs
CC BY-SA 3.0
2015-05-01T10:42:32.290Z
Difference between first and last day of week is 6, and using less than or equal to :) but you are probably right, should be 7 and less than.
Douglas McDonald
CC BY-SA 3.0
2015-04-30T12:38:45.740Z
2015-05-01T10:44:56.967Z
2015-05-01T10:44:56.967Z
Douglas McDonald
<p>I've created a custom route for my entries based on week like so:</p>

<pre><code>'events/(?P&lt;year&gt;\d{4})/(?P&lt;week&gt;\d{2})' =&gt; 'events/_weekindex',
</code></pre>

<p>I know i can group entries by week like this:</p>

<pre><code>{% set allEntriesByWeek = allEntries|group('postDate|date('Y-W')') %}
</code></pre>

<p>What i'm not quite sure how to do is how to show navigation ONLY for weeks that have entries present, and then of course output the entries in my template when those navigation items are clicked.</p>

<entries><routes><pagination><array><group>
Pagination / Custom Routes (Based on Entry Existing)
# Pagination / Custom Routes (Based on Entry Existing)

(Asked by: username_0 on 2015-04-30)

I've created a custom route for my entries based on week like so:
'events/(?P\d{4})/(?P\d{2})' => 'events/_weekindex',

I know i can group entries by week like this:
{% set allEntriesByWeek = allEntries|group('postDate|date('Y-W')') %}

What i'm not quite sure how to do is how to show navigation ONLY for weeks that have entries present, and then of course output the entries in my template when those navigation items are clicked.

**Tags:** entries, routes, pagination, array, group

---

## 1 answers

### Answer by username_1 on 2015-04-30. Score: 4 | Accepted answer

For generating the nav, this should work.
{% set allEntriesByWeek = allEntries|group("postDate|date('Y-W')") %}
{% for week, entry in allEntriesByWeek %}
    {{ week }}
{% endfor %}

For grabbing entries (using the 'week' and 'year' variables passed via the route).
{% set startDate = now.setISODate(year, week) %}
{% set endDate = startDate|date_modify("+7 days") %}
{% set entries = craft.entries.section('events').postDate('and', '>= ' ~ startDate, '< ' ~ endDate ) %}
{% for entry in entries %}
    {{ entry.title }}
{% endfor %}

For pagination.
Next Week
Previous Week

> **Comments:**
> **username_2**: Why is it that your weeks are only 6 days long?  
> **username_1**: Difference between first and last day of week is 6, and using less than or equal to :) but you are probably right, should be 7 and less than.  

---

