I'm stuck on an issue where I have to paginate a list of entries that would be sorted by category title. So basically, I need to:
- fetch entries in the 'project' section
- sort those entries by the 'projectYear' category title (2016->2002)
- paginate it (limit 5 for example)
- sort entries by title (a->z)
The output expected would look like this
Page 1
2016
Project A
Project B
Project C
2015
Project D
Project E
Page 2
2015
Project F
Project G
2012
Project H
2010
Project I
Project J
At the moment, I have this "working"
{% set categories = craft.categories({
group: 'projectYear',
title: 'not Unknown',
order: 'title desc'
}) %}
{% set allProjects = craft.entries({
section: 'projects',
relatedTo: categories,
order: 'title asc'
}) %}
{% for year, projectsInYear in allProjects | group('projectYear.first().title') %}
{{ year }}
{% for project in projectsInYear %}
{{ project.title }}
{% endfor %}
{% endfor %}
By "working" I mean that it outputs all project entries sorted by title & grouped by projectYear... but those projectYear groups are not sorted by title and it also lacks a pagination system.
FYI: If I limit to 5 in craft.entries, it outputs the 5 first entries sorted by title and groups them by year after that. Instead, I want it entries to be first grouped by year and then get the 5 of those first entries.
Could anybody help me figure out how I can get the output I want or lead me in the right direction?
Thanks!
PS: we used postDate originally and it worked great, but we had to move from using postDate so it's not a possibility anymore.