Jump to content

Recommended Posts

Posted

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

Posted

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.

Posted

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

Posted

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.

Posted

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.

Posted

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.

Posted

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.

Posted

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

Posted

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>";}
  • Like 1

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
  • Recently Browsing   0 members

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