Jump to content

Next / previous page linking


Marty Walker
 Share

Recommended Posts

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

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

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

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

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

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

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 account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...