Prev/next links with untranslated pages

I created a prev/next navigation with $page->prevVisible() and $page->nextVisible() to navigate through visible subpages (news items). This works great for the default language.

The problem is, that not all of these pages are translated and by using the prev/next links the untranslated pages also appear.

Are there existing solutions for this?

My idea is to collect all translated pages in a collection, find the current position and check if there are elements before/after. But maybe there a better/easier solutions?

Note that prev() and next() don’t work with custom collections, only the protected methods _next() and _prev() do. You can, however, create custom collection methods to achieve this, see this post: Prev() and next() with custom collection

1 Like