I’m attempting to add ‘next’ and ‘previous’ links that navigate between pages in the same content model. The content model can be ordered by the editor with drag and drop.
I’ve figured out how to apply the ‘next’ from one of your support articles, using skip and first. However, I’m struggling to do the same for ‘previous’ as it doesn’t seem like you can decrement a variable.
Managed to solve this by two separate queries. The first to get the current post’s position. Then -2 (I realised, not -1 as this would skip to the current position) to that value and use this as $position for this second query. Was obviously thinking about this in the wrong way
And depending on your framework, like if you’re using something like Next.js to prebuild pages and some sort of global router + state for routing, it might make sense to just prefetch all the projects and their positions ahead of time, store that in the global state / context and pass that along to the router, so it doesn’t have to calculate prev/next pages on each client page load (which might take a couple seconds).