Answers.Body: <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>
  
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2015-05-01T07:35:04.850Z
Answers.Text: Why is it that your weeks are only 6 days long?
Answers.UserDisplayName: carlcs
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2015-05-01T10:42:32.290Z
Answers.Text: 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.
Answers.UserDisplayName: Douglas McDonald
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2015-04-30T12:38:45.740Z
Answers.LastActivityDate: 2015-05-01T10:44:56.967Z
Answers.LastEditDate: 2015-05-01T10:44:56.967Z
Answers.UserDisplayName: Douglas McDonald
Body: <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>
  
Tags: <entries><routes><pagination><array><group>
Title: Pagination / Custom Routes (Based on Entry Existing)
ThreadText: # 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<year>\d{4})/(?P<week>\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 %}
      <li><a href="events/{{ week|replace('-','/') }}">{{ week }}</a></li>
  {% 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.
  
  ```
  <a href="events/{{ startDate|date_modify('+7 days')|date('Y/W') }}">Next Week</a>
  <a href="events/{{ startDate|date_modify('-7 days')|date('Y/W') }}">Previous Week</a>
  
  ```
  
  > **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.  
  
  ---
  
  