double Posted February 3, 2023 Share Posted February 3, 2023 What's the best way to return 5 next and 5 previous pages? If there're no 5 pages return what's remaining Should I use nextUntil() and prevUntil()? Link to comment Share on other sites More sharing options...
bernhard Posted February 3, 2023 Share Posted February 3, 2023 I don't know of a built in way but I'm happy to learn ? Not sure if that's the best way to do it but it works: $i = 0; $prev = new PageArray(); $next = new PageArray(); $p = $n = $page; while($i++ < 5) { if($p and $p = $p->prev and $p->id) $prev->add($p); if($n and $n = $n->next and $n->id) $next->add($n); } db($prev, "prev"); db($next, "next"); 1 Link to comment Share on other sites More sharing options...
Jan Romero Posted February 3, 2023 Share Posted February 3, 2023 Haven’t tested but isn’t this just $page->prevAll('limit=5') and $page->nextAll('limit=5')? https://processwire.com/api/ref/page/prev-all/ 2 3 Link to comment Share on other sites More sharing options...
bernhard Posted February 3, 2023 Share Posted February 3, 2023 Nice! Works ? Thx! Link to comment Share on other sites More sharing options...
double Posted February 3, 2023 Author Share Posted February 3, 2023 1 hour ago, Jan Romero said: Haven’t tested but isn’t this just $page->prevAll('limit=5') and $page->nextAll('limit=5')? https://processwire.com/api/ref/page/prev-all/ Works perfectly! Thanks a lot! Link to comment Share on other sites More sharing options...
Gideon So Posted February 4, 2023 Share Posted February 4, 2023 10 hours ago, Jan Romero said: Haven’t tested but isn’t this just $page->prevAll('limit=5') and $page->nextAll('limit=5')? https://processwire.com/api/ref/page/prev-all/ WOW! Learn something new. Gideon 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