Marty Walker Posted February 12, 2011 Share Posted February 12, 2011 Hi, This is my first post here and I'm a bit of a php noob - but willing to learn nonetheless. I really like approach of this CMS. I think it'd be a fantastic offering to a lot of my clients. My first question (probably of many) is regarding next/previous page linking. I'm picking through the demo site code and say, for example I'm on the About Us > Child page example 1. How would I go about adding a next / previous page link that works only on that level? Thanks & regards Martin Link to comment Share on other sites More sharing options...
ryan Posted February 12, 2011 Share Posted February 12, 2011 That's a very good question. I was just going to reply that you should use the next/prev page methods, until I realized I haven't yet implemented this part in PW2 (it us in PW1). Surprisingly, the need just hadn't yet come up in PW2 (at least in my projects). I will implement, hopefully today or tomorrow and then reply again with an example of how to use. Link to comment Share on other sites More sharing options...
Jim Yost Posted February 12, 2011 Share Posted February 12, 2011 Hi Martin, Welcome to the forums! To answer your question, you may want to take a look here to get a general idea of the Pagination module: http://processwire.com/api/modules/markup-pager-nav/ That should be a good place to start. You will also want to think about using a different selector to get the sibling pages instead of a general list of pages. Maybe you want to sort them by page name, etc. <?php $results = $page->siblings("sort=name"); echo $results->render(); Instead of the code in the example: <?php $results = $pages->find("id>1, limit=10, sort=title"); echo $results->render(); I actually haven't used this myself yet, but hopefully this will give you a good place to start! Good Luck! -Jim Link to comment Share on other sites More sharing options...
Jim Yost Posted February 12, 2011 Share Posted February 12, 2011 Ryan, The above would not work for what he wants? Link to comment Share on other sites More sharing options...
ryan Posted February 12, 2011 Share Posted February 12, 2011 Jim, actually I'm thinking Martin's talking about the next/previous sibling, rather than pagination. Though reading it again, now I'm not sure. Martin, can you confirm? Either way, I do need to add those next/prev sibling API functions. Link to comment Share on other sites More sharing options...
Jim Yost Posted February 12, 2011 Share Posted February 12, 2011 Yeah, I realized that the Pagination Module works for search results and it displays an entire list of pages as well as the page #'s. He just want's to see the page #'s. Link to comment Share on other sites More sharing options...
Marty Walker Posted February 13, 2011 Author Share Posted February 13, 2011 Hi everyone, Ryan, that's exactly what I meant. Jim, actually I'm thinking Martin's talking about the next/previous sibling, rather than pagination. Though reading it again, now I'm not sure. Martin, can you confirm? Either way, I do need to add those next/prev sibling API functions. Link to comment Share on other sites More sharing options...
ryan Posted February 13, 2011 Share Posted February 13, 2011 I've added the next() and prev() functions and properties to the Page class, so that you can now use them. I've updated the reference information here: http://processwire.com/api/variables/page/ Example: <?php echo "<p>The next page is: {$page->next->title}</p>"; echo "<p>The previous page is: {$page->prev->title}</p>"; ...but be sure to see the reference as there are more options and considerations (for large scale) on these kinds of functions. Link to comment Share on other sites More sharing options...
Marty Walker Posted February 14, 2011 Author Share Posted February 14, 2011 Thanks again Ryan. Another noob PHP question. Can I use a conditional to check whether I'm on a first or last page? That way it only outputs 'next page' or 'previous page' if there actually is one. Regards Martin Link to comment Share on other sites More sharing options...
Marty Walker Posted February 14, 2011 Author Share Posted February 14, 2011 I think I have it sorted. if($page->prev->id) {echo "<p class='next'><a href='{$page->prev->url}'>prev</a></p>";} if($page->next->id) {echo "<p class='prev'><a href='{$page->next->url}'>next</a></p>";} 1 Link to comment Share on other sites More sharing options...
ryan Posted February 15, 2011 Share Posted February 15, 2011 Martin, sorry I couldn't reply earlier. I was out of the office yesterday. But the solution you found is the right one. This page has some additional information on it too: http://processwire.com/api/types/nullpage/ 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