$next page but also with subpages and loop

Hi, I want to insert a button for going to the next listed project-page.

I’ve found the following:

<?php if($next = $page->nextListed()): ?>
<a href="<?= $next->url() ?>">> <?php echo $next?></a>
<?php endif ?>

I inserted "> <?php echo $next?>", so the button is named like the next project, but it also displays the surrounding folder. So what I want to achieve is a button name like this: “> Project-2” and for now it displays “> Projects/Project-2”
Is there a way to remove the folder name? If I type “$next = $subpage” instead of “$next = $page”, the page crashes.

Thanks!

$next gives you the page object. You can use $next->title() to get the title (just like you get the url with $next->url()).

1 Like

Thanks, that works for me as simple as it is…

Is there a way to loop my last project to the first, so I can jump to the first project again as soon as I reached the last project?

Another quick question:
I have project-pages and also project-pages with a submenu of project pages (see attached screenshot)
When I jump through the pages with the $next function, the pages with a submenu will not automatically jump to the first inner project page.

I thought about giving every page I want to jump through a specific tag and then tell the $next function to only jump to next page which has this tag… but I think there is a much simpler solution

Do you have any idea? :slight_smile:


In the Screenshot, project-1,2,4 are simple project pages whereas project-3 has its pages inside – I would like to jump from project-2 directly to project-3-1 and also the other way around (project-3-7 → project-4)

You can pass the collection you are interested in as argument to the prev()/next() methods.

Thanks, that solved my problem - I was not aware of collections yet. :slight_smile: