Answers.Body: <p>Welcome to craft </p>
  
  <p>There is a example for a archive on the official page: <a href="https://craftcms.com/guides/creating-an-archive-page-for-entries" rel="nofollow noreferrer">Creating an ​“Archive” Page for Entries</a></p>
  
  <p>Maybe this fit's your use case.</p>
  
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2019-05-21T15:04:31.290Z
Answers.Text: Thank you, it nearly fits. The paging in the article would display every year from the first entry to now, even if there is a year without entries. So for my example above this would result in 2019 | 2018 | 2017 | 2016 instead of just 2019 | 2018 | 2016.
Answers.UserDisplayName: Phillip
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2019-05-21T13:49:45.383Z
Answers.LastActivityDate: 2019-05-21T13:49:45.383Z
Answers.UserDisplayName: KSPR
Answers.Body: <p>Here's video tutorial series about creating date-based navigation for posts:</p>
  
  <p><a href="https://craftquest.io/courses/creating-content-archives" rel="nofollow noreferrer">https://craftquest.io/courses/creating-content-archives</a></p>
  
  <p>Keep in mind that Craft Quest is not a free site and you need purchase access to view most videos.</p>
  
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2019-05-21T17:51:19.037Z
Answers.LastActivityDate: 2019-05-21T17:51:19.037Z
Answers.UserDisplayName: Piotr Pogorzelski
Body: <p>Is there a best practice for a paging based on the years of entries (instead of page numbers)?</p>
  
  <p>Example:
  I have 3 records with post dates 2019-01-01 2018-01-01 and 2016-01-01. So my paging should look like this:</p>
  
  <p>2019 | 2018 | 2016</p>
  
  <p>It is easy to fetch the needed info with a raw query like:</p>
  
  <pre><code>{% set pagingYears = craft.query()
      .select('DISTINCT YEAR(postDate)')
      .from('entries')
      .where({'sectionId': 1})
      .column()
  %}
  </code></pre>
  
  <p>But does craft provide some components or a better way to solve such a problem?</p>
  
Tags: <craft3><query>
Title: Best practice for year based paging
ThreadText: # Best practice for year based paging
  
  (Asked by: username_0 on 2019-05-21)
  
  Is there a best practice for a paging based on the years of entries (instead of page numbers)?
  
  Example:
  I have 3 records with post dates 2019-01-01 2018-01-01 and 2016-01-01. So my paging should look like this:
  
  2019 | 2018 | 2016
  
  It is easy to fetch the needed info with a raw query like:
  
  ```
  {% set pagingYears = craft.query()
      .select('DISTINCT YEAR(postDate)')
      .from('entries')
      .where({'sectionId': 1})
      .column()
  %}
  
  ```
  
  But does craft provide some components or a better way to solve such a problem?
  
  **Tags:** craft3, query
  
  
  ---
  
  ## 2 answers
  
  ### Answer by username_1 on 2019-05-21. Score: 2
  
  Welcome to craft
  
  There is a example for a archive on the official page: [Creating an ​“Archive” Page for Entries](https://craftcms.com/guides/creating-an-archive-page-for-entries)
  
  Maybe this fit's your use case.
  
  > **Comments:**
  > **username_0**: Thank you, it nearly fits. The paging in the article would display every year from the first entry to now, even if there is a year without entries. So for my example above this would result in 2019 | 2018 | 2017 | 2016 instead of just 2019 | 2018 | 2016.  
  
  ---
  
  ### Answer by username_2 on 2019-05-21. Score: 2
  
  Here's video tutorial series about creating date-based navigation for posts:
  
  <https://craftquest.io/courses/creating-content-archives>
  
  Keep in mind that Craft Quest is not a free site and you need purchase access to view most videos.
  
  
  ---
  
  