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)')
    .where({'sectionId': 1})

But does craft provide some components or a better way to solve such a problem?

2 Answers 2


Welcome to craft 👋

There is a example for a archive on the official page: Creating an ​“Archive” Page for Entries

Maybe this fit's your use case.

  • 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.
    – Phillip
    May 21, 2019 at 15:04

Here's video tutorial series about creating date-based navigation for posts:


Keep in mind that Craft Quest is not a free site and you need purchase access to view most videos.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.