Answers.Body: <p>The code on the left is what you want to use... Here are the general steps to follow to put everything together.</p>
  
  <p>Since you're creating an archive page, you have to explicitly tell Craft what to do. First step then is to set the URL to something like:</p>
  
  <pre><code>href="/chamber-news/archive/{{ month }}/{{ year }}"
  </code></pre>
  
  <p>Then set up a template (my example uses one named "chamber-archive") which looks to the URL for the month &amp; year to determine which entries to load. (<a href="https://craftcms.stackexchange.com/a/2875/103">altered code borrowed from this answer</a>)</p>
  
  <pre><code>{% set month = craft.request.segment(3) %}
  {% set year = craft.request.segment(4) %}
  
  {% set firstDay = now | date_modify('first day of ' ~ month ~ ' ' ~ year ~ ' 00:00:00') %}
  {% set lastDay = now | date_modify('last day of ' ~ month ~ ' ' ~ year ~ ' 23:59:59') %}
  
  {% set archive  = craft.entries.section('sectionNameHere').postDate('and', '&gt;= ' ~ firstDay, '&lt;= ' ~ lastDay) %}
  </code></pre>
  
  <p>Then you need to set up routing to tell Craft to use this template for this URL pattern.</p>
  
  <p><a href="https://i.sstatic.net/OsoWY.png" rel="nofollow noreferrer"><img src="https://i.sstatic.net/OsoWY.png" alt="enter image description here"></a></p>
  
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2015-09-22T11:57:19.693Z
Answers.Text: Sorry, I can't get this to work.  I've followed your instruction but it's just loading the _layout template :(
Answers.UserDisplayName: Martin
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2015-09-22T15:00:48.193Z
Answers.Text: Small note to this: You'd be able to simply call the `month` and `year` tokens as `{{ month }}` and `{{ year }}`, instead of manually setting them. Craft passes your tokens to route templates as their variable, per [documentation](http://buildwithcraft.com/docs/routing#dynamic-routes).
Answers.UserDisplayName: Taylor Daughtry
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2015-09-22T16:09:21.837Z
Answers.Text: Very good to know @TaylorDaughtry. Thank you for adding this!
Answers.UserDisplayName: Anna_MediaGirl
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2015-09-22T16:13:19.260Z
Answers.Text: @martin Show me screenshots of each piece that you've completed please. Does it appear that just the routing part isn't working?
Answers.UserDisplayName: Anna_MediaGirl
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2015-09-22T20:12:02.643Z
Answers.Text: So I have the following so far... https://i.sstatic.net/bzGsQ.jpg
  
  I'm not sure if it has any bearing but i'm also using this method for directing Structure entries to their own templates.  http://craftcms.stackexchange.com/questions/96/how-can-i-route-a-specific-entry-in-a-structure-section-to-its-own-template
  
  Many thanks
  
  Martin
Answers.UserDisplayName: Martin
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2015-09-22T20:23:22.027Z
Answers.Text: Try adding "Hello World" to the news-archive.twig template to see if it's loading but just not showing entries... That will help you decide in which direction to troubleshoot. Also, set the URL in chamber-news.twig to start with a slash at the beginning. Additionally, print out {{ month }} and {{ year }} in news-archive.twig to ensure the variables are getting loaded correctly. You may need to add a slash at the start of the route URL as well.
Answers.UserDisplayName: Anna_MediaGirl
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2015-09-22T20:24:43.103Z
Answers.Text: Also, you can use {{ month | lower }} when creating the URL to make the month name lower case.
Answers.UserDisplayName: Anna_MediaGirl
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2015-09-23T08:30:58.397Z
Answers.Text: I've tried the "Hello World" thing and it doesn't show.  I've also tried the slash.  In the Docs it says not to use a slash at the beginning of a route.  I know it's only loading the _layout template because the page that does load just contains the _layout info.  Curiously I tried this and it does load the template http://cliveportman.co.uk/code/archives-by-month-using-craft-cms, however it still doesn't show any content!? :(
Answers.UserDisplayName: Martin
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2015-09-23T14:43:06.503Z
Answers.Text: That example is pretty much the same method so use that code if you have it working.
Answers.UserDisplayName: Anna_MediaGirl
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2015-09-25T08:31:46.717Z
Answers.Text: Thanks... but although it shows the right template, it doesn't show any content :/
Answers.UserDisplayName: Martin
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2015-09-25T16:47:57.843Z
Answers.Text: Please post the contents of your template somewhere.
Answers.UserDisplayName: Anna_MediaGirl
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2015-09-21T17:51:05.483Z
Answers.LastActivityDate: 2015-09-21T18:06:05.387Z
Answers.LastEditDate: 2017-04-13T12:51:00.160Z
Answers.UserDisplayName: Anna_MediaGirl
Answers.Body: <p>Why not use <a href="https://buildwithcraft.com/docs/templating/entrymodel#getUrl" rel="nofollow">getUrl</a> instead of getLink? </p>
  
  <pre><code>&lt;li&gt;&lt;a href="{{ entry.getUrl() }}"&gt;{{ month }} ({{ entries | length }})&lt;/a&gt;&lt;/li&gt;
  </code></pre>
  
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2015-09-22T14:45:59.980Z
Answers.LastActivityDate: 2015-09-22T14:45:59.980Z
Answers.UserDisplayName: Chris
Answers.Body: <p>So P&amp;T chipped in to help and of course solved my plight immediately :D</p>
  
  <p>For anyone else who might encounter a similar scenario I'm posting the solution.</p>
  
  <p>On the page containing the archive list:</p>
  
  <pre><code>{% set allEntries = craft.entries.section('sectionName').limit(null) %}
  
  &lt;ul id="archive"&gt;
      {% for year, entriesInYear in allEntries | group("postDate.year") %}
  
          {% set counter = ( counter | default(0) ) + 1 %}
  
          &lt;li class="year{{ counter }}"&gt;
              &lt;a href="#year{{ counter }}"&gt;{{ year }}&lt;/a&gt;
  
              &lt;ul&gt;
                  {% for month, entries in entriesInYear | group("postDate|date('F')") %}
                      &lt;li&gt;&lt;a href="{{ siteUrl }}path/to-page/{{ month }}-{{ year }}"&gt;{{ month }}&amp;nbsp;({{ entries|length }})&lt;/a&gt;&lt;/li&gt;
                  {% endfor %}
              &lt;/ul&gt;
          &lt;/li&gt;
  
      {% endfor %}
  &lt;/ul&gt;
  </code></pre>
  
  <p>Then on the actual archive page (I added this at the top of the page):</p>
  
  <pre><code>{% set month = craft.request.segment(3) %}
  {% set year = craft.request.segment(4) %}
  
  {% set firstDay = now | date_modify('first day of ' ~ month ~ ' ' ~ year ~ ' 00:00:00') %}
  {% set lastDay = now | date_modify('last day of ' ~ month ~ ' ' ~ year ~ ' 23:59:59') %}
  </code></pre>
  
  <p>Then where you want the info to appear:</p>
  
  <pre><code>{% set archive  = craft.entries.section('sectionName').postDate('and', '&gt;= ' ~ firstDay, '&lt;= ' ~ lastDay) %}
  
  &lt;ul&gt;
      {% for entry in archive %}         
          &lt;li&gt;
              &lt;h3&gt;&lt;a href="{{ entry.url }}"&gt;{{ entry.title }}&lt;/a&gt;&lt;/h3&gt;
              {{ entry.body }}
  
              &lt;p class="more"&gt;&lt;a href="{{ entry.url }}"&gt;read more&lt;/a&gt;&lt;/p&gt;
  
              &lt;div&gt;
                  &lt;p&gt;{{ entry.postDate | date("d") }} &lt;span&gt;{{ entry.postDate | date("M") }}&lt;/span&gt;&lt;/p&gt;
              &lt;/div&gt;
          &lt;/li&gt;
      {% endfor %}
  &lt;/ul&gt;
  </code></pre>
  
  <p>Now here's the bit that caused the grief...  Instead of having <code>'month'-'year'</code> as part of the route, P&amp;T suggested using just <code>'*'</code>.</p>
  
  <p><a href="https://i.sstatic.net/7w20g.jpg"><img src="https://i.sstatic.net/7w20g.jpg" alt="Route using asterisk"></a></p>
  
  <p>Or.. as P&amp;T put it:</p>
  
  <blockquote>
    <p>Your dynamic route is set with the Month and Year token. If you look at the list of available tokens, you will see that Month and Year follow a specific format, which the URLs you set up in your menu do not follow. Therefore, those URLs do not follow the pattern you set in the Route and you get a 404 page.</p>
  </blockquote>
  
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2015-10-05T11:19:50.733Z
Answers.LastActivityDate: 2015-10-05T17:17:05.403Z
Answers.LastEditDate: 2015-10-05T17:17:05.403Z
Answers.UserDisplayName: Martin
Body: <p>With a bit of looking around i've got the following code on my News landing page:</p>
  
  <pre><code>  {% set allEntries = craft.entries.section('chambersNews').limit(null) %}
    &lt;ul id="archive"&gt;
    {% for year, entriesInYear in allEntries | group("postDate.year") %}
        &lt;li&gt;&lt;a href=""&gt;{{ year }}&lt;/a&gt;
          &lt;ul&gt;
          {% for month, entries in entriesInYear | group("postDate|date('F')") %}
              &lt;li&gt;&lt;a href=""&gt;{{ month }}&amp;nbsp;({{ entries|length }})&lt;/a&gt;&lt;/li&gt;
          {% endfor %}
          &lt;/ul&gt;
        &lt;/li&gt;
    {% endfor %}
    &lt;/ul&gt;
  </code></pre>
  
  <p>Using <code>&lt;li&gt;&lt;a href=""&gt;{{ month }}&amp;nbsp;({{ entries|length }})&lt;/a&gt;&lt;/li&gt;</code>  I get the desired result (visually), see attached image.  If I use <code>&lt;li&gt;{{ entry.getLink() }}&lt;/li&gt;</code> I get the result shown on the right of the attached image.</p>
  
  <p>In both instances I only get a link to the first segment (also shown in the attached image).</p>
  
  <p>What I would like to do is have the Months link to a page that lists just the articles from that month (I don't need the year to link).</p>
  
  <p>I assume I need to add a dynamic link into the href but how and what?</p>
  
  <p>Many thanks in advance.</p>
  
  <p>Martin</p>
  
  <p><a href="https://i.sstatic.net/hpIi5.jpg"><img src="https://i.sstatic.net/hpIi5.jpg" alt="Need the left hand side linking through to a page showing articles from a chosen month"></a></p>
  
Tags: <archives>
Title: Linking and showing archive by month
ThreadText: # Linking and showing archive by month
  
  (Asked by: username_0 on 2015-09-17)
  
  With a bit of looking around i've got the following code on my News landing page:
  
  ```
    {% set allEntries = craft.entries.section('chambersNews').limit(null) %}
    <ul id="archive">
    {% for year, entriesInYear in allEntries | group("postDate.year") %}
        <li><a href="">{{ year }}</a>
          <ul>
          {% for month, entries in entriesInYear | group("postDate|date('F')") %}
              <li><a href="">{{ month }}&nbsp;({{ entries|length }})</a></li>
          {% endfor %}
          </ul>
        </li>
    {% endfor %}
    </ul>
  
  ```
  
  Using `<li><a href="">{{ month }}&nbsp;({{ entries|length }})</a></li>` I get the desired result (visually), see attached image. If I use `<li>{{ entry.getLink() }}</li>` I get the result shown on the right of the attached image.
  
  In both instances I only get a link to the first segment (also shown in the attached image).
  
  What I would like to do is have the Months link to a page that lists just the articles from that month (I don't need the year to link).
  
  I assume I need to add a dynamic link into the href but how and what?
  
  Many thanks in advance.
  
  username_0
  
  [![Need the left hand side linking through to a page showing articles from a chosen month](https://i.sstatic.net/hpIi5.jpg)](https://i.sstatic.net/hpIi5.jpg)
  
  **Tags:** archives
  
  
  ---
  
  ## 3 answers
  
  ### Answer by username_0 on 2015-10-05. Score: 9 | Accepted answer
  
  So P&T chipped in to help and of course solved my plight immediately :D
  
  For anyone else who might encounter a similar scenario I'm posting the solution.
  
  On the page containing the archive list:
  
  ```
  {% set allEntries = craft.entries.section('sectionName').limit(null) %}
  
  <ul id="archive">
      {% for year, entriesInYear in allEntries | group("postDate.year") %}
  
          {% set counter = ( counter | default(0) ) + 1 %}
  
          <li class="year{{ counter }}">
              <a href="#year{{ counter }}">{{ year }}</a>
  
              <ul>
                  {% for month, entries in entriesInYear | group("postDate|date('F')") %}
                      <li><a href="{{ siteUrl }}path/to-page/{{ month }}-{{ year }}">{{ month }}&nbsp;({{ entries|length }})</a></li>
                  {% endfor %}
              </ul>
          </li>
  
      {% endfor %}
  </ul>
  
  ```
  
  Then on the actual archive page (I added this at the top of the page):
  
  ```
  {% set month = craft.request.segment(3) %}
  {% set year = craft.request.segment(4) %}
  
  {% set firstDay = now | date_modify('first day of ' ~ month ~ ' ' ~ year ~ ' 00:00:00') %}
  {% set lastDay = now | date_modify('last day of ' ~ month ~ ' ' ~ year ~ ' 23:59:59') %}
  
  ```
  
  Then where you want the info to appear:
  
  ```
  {% set archive  = craft.entries.section('sectionName').postDate('and', '>= ' ~ firstDay, '<= ' ~ lastDay) %}
  
  <ul>
      {% for entry in archive %}         
          <li>
              <h3><a href="{{ entry.url }}">{{ entry.title }}</a></h3>
              {{ entry.body }}
  
              <p class="more"><a href="{{ entry.url }}">read more</a></p>
  
              <div>
                  <p>{{ entry.postDate | date("d") }} <span>{{ entry.postDate | date("M") }}</span></p>
              </div>
          </li>
      {% endfor %}
  </ul>
  
  ```
  
  Now here's the bit that caused the grief... Instead of having `'month'-'year'` as part of the route, P&T suggested using just `'*'`.
  
  [![Route using asterisk](https://i.sstatic.net/7w20g.jpg)](https://i.sstatic.net/7w20g.jpg)
  
  Or.. as P&T put it:
  
  > Your dynamic route is set with the Month and Year token. If you look at the list of available tokens, you will see that Month and Year follow a specific format, which the URLs you set up in your menu do not follow. Therefore, those URLs do not follow the pattern you set in the Route and you get a 404 page.
  
  
  ---
  
  ### Answer by username_1 on 2015-09-21. Score: 1
  
  The code on the left is what you want to use... Here are the general steps to follow to put everything together.
  
  Since you're creating an archive page, you have to explicitly tell Craft what to do. First step then is to set the URL to something like:
  
  ```
  href="/chamber-news/archive/{{ month }}/{{ year }}"
  
  ```
  
  Then set up a template (my example uses one named "chamber-archive") which looks to the URL for the month & year to determine which entries to load. ([altered code borrowed from this answer](https://craftcms.stackexchange.com/a/2875/103))
  
  ```
  {% set month = craft.request.segment(3) %}
  {% set year = craft.request.segment(4) %}
  
  {% set firstDay = now | date_modify('first day of ' ~ month ~ ' ' ~ year ~ ' 00:00:00') %}
  {% set lastDay = now | date_modify('last day of ' ~ month ~ ' ' ~ year ~ ' 23:59:59') %}
  
  {% set archive  = craft.entries.section('sectionNameHere').postDate('and', '>= ' ~ firstDay, '<= ' ~ lastDay) %}
  
  ```
  
  Then you need to set up routing to tell Craft to use this template for this URL pattern.
  
  [![enter image description here](https://i.sstatic.net/OsoWY.png)](https://i.sstatic.net/OsoWY.png)
  
  > **Comments:**
  > **username_0**: Sorry, I can't get this to work.  I've followed your instruction but it's just loading the _layout template :(  
  > **username_2**: Small note to this: You'd be able to simply call the `month` and `year` tokens as `{{ month }}` and `{{ year }}`, instead of manually setting them. Craft passes your tokens to route templates as their variable, per [documentation](http://buildwithcraft.com/docs/routing#dynamic-routes).  
  > **username_1**: Very good to know @username_2. Thank you for adding this!  
  > **username_1**: @username_0 Show me screenshots of each piece that you've completed please. Does it appear that just the routing part isn't working?  
  > **username_0**: So I have the following so far... https://i.sstatic.net/bzGsQ.jpg  I'm not sure if it has any bearing but i'm also using this method for directing Structure entries to their own templates.  http://craftcms.stackexchange.com/questions/96/how-can-i-route-a-specific-entry-in-a-structure-section-to-its-own-template  Many thanks  username_0  
  > **username_1**: Try adding "Hello World" to the news-archive.twig template to see if it's loading but just not showing entries... That will help you decide in which direction to troubleshoot. Also, set the URL in chamber-news.twig to start with a slash at the beginning. Additionally, print out {{ month }} and {{ year }} in news-archive.twig to ensure the variables are getting loaded correctly. You may need to add a slash at the start of the route URL as well.  
  > **username_1**: Also, you can use {{ month | lower }} when creating the URL to make the month name lower case.  
  > **username_0**: I've tried the "Hello World" thing and it doesn't show.  I've also tried the slash.  In the Docs it says not to use a slash at the beginning of a route.  I know it's only loading the _layout template because the page that does load just contains the _layout info.  Curiously I tried this and it does load the template http://cliveportman.co.uk/code/archives-by-month-using-craft-cms, however it still doesn't show any content!? :(  
  > **username_1**: That example is pretty much the same method so use that code if you have it working.  
  > **username_0**: Thanks... but although it shows the right template, it doesn't show any content :/  
  > **username_1**: Please post the contents of your template somewhere.  
  
  ---
  
  ### Answer by username_3 on 2015-09-22. Score: 0
  
  Why not use [getUrl](https://buildwithcraft.com/docs/templating/entrymodel#getUrl) instead of getLink?
  
  ```
  <li><a href="{{ entry.getUrl() }}">{{ month }} ({{ entries | length }})</a></li>
  
  ```
  
  
  ---
  
  