jploch Posted October 9, 2015 Share Posted October 9, 2015 Hey guys! This is probably a total newbi question, but I cant figure it out myself. I use two links to get to the previous or next page. When the user is on the last page, I want the next link to show the first page. When the user is on the first page I want the previous link to show the last page. How can I do this with the API? This is my second site with PW, so Iam still trying to figure things out. Here is my code: <ul id="nav"> <li class="nav-left"><a href="<?php echo $page->prev->url; ?>" class="arrow"><img src="<?php echo $config->urls->templates?>img/site/arrow_left.svg"></a></li> <li class="nav-right"><a href="<?php echo $page->next->url; ?>" class="arrow"><img src="<?php echo $config->urls->templates?>img/site/arrow_right.svg"></a></li> </ul> Thx! Link to comment Share on other sites More sharing options...
LostKobrakai Posted October 9, 2015 Share Posted October 9, 2015 $prev = $page->prev->id ? $page->prev : $page->siblings->last(); $next = $page->next->id ? $page->next : $page->siblings->first(); 1 Link to comment Share on other sites More sharing options...
ceberlin Posted December 12, 2015 Share Posted December 12, 2015 I wonder if there such a quick way to sort and filter this? What about doing a next|prev|last|first roundtrips for an ordered selection of the page's siblings only? This does not work (always true): $prev = ($page->prev($myfilter)->id) ? $page->prev($myfilter) : $page->siblings($myfilter)->last(); $next = ($page->next($myfilter)->id) ? $page->next($myfilter) : $page->siblings($myfilter)->first(); There must be something wrong with my thinking here... Link to comment Share on other sites More sharing options...
ceberlin Posted March 13, 2016 Share Posted March 13, 2016 I solved it by doing it a little bit differently - now sorting and filtering works: $siblings = $page->siblings("sort=date"); $prev = $siblings->getNext($page); $next = $siblings->getPrev($page); "Last" and "first" can be tested easily: if you reach the last or first item, $next or §prev return NULL (or have no ID) - LostKobrakai's code works great to catch that. So the difference was that I build my own pageArray ($siblings) instead of using $page, as suggested, to enable sorting. It was so easy to solve that I did not see it right before my eyes 2 Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now