I have portfolio section that has a ‘portfolio’ category attached to it, which has categories ‘2D’ and ‘3D’.
There are 3 templates:
- The index template shows a list of all the entries in the portfolio section.
- The categories template shows the entries within a specific category.
- The entry template shows a single entry.
On the index page (/portfolio) you can click on 'All', '2D' and '3D' whereby 'All' takes you the index page, and 2D and 3D lead to /portfolio/2D and 3D (the categories template). Click on any item in the list and you go to the entry page.
On the entry template, I have a simple ‘previous entry’ and ‘next entry’ browsing navigation, using:
{% set params = {section: 'portfolio', orderBy: 'postDate desc', limit: null} %}
{% set entry_prev = entry.getPrev(params) %}
{% set entry_next = entry.getNext(params) %}
The thing is, this navigation always browses through all of the entries, regardless of what category an entry is in. And that's fine when you've reached the page from the index page, where all of the entries are listed. But I’m trying to make it so when you click an entry on the categories page, and you are then taken to this entry page, the browsing navigation (previous and next entry) takes into account what category you’re in. I use a simple cookie or getQuery() to set and get this information. That way, when you've clicked on an entry in the list with 2D items, you don't get entries from other categories in the prev/next navigation, but when you've clicked on the same item on the index page, you do get to navigate through all of the entries.
I’ve tried:
{% set params = craft.entries.section('portfolio').relatedTo('2d').orderBy('postDate desc').limit(10).all() %}
But this does not work: the navigation still includes entries that do not have the 2d category.
Anyone have any idea how to achieve this?