Jump to content

Next and Prev article - how to get it based on the backend structure


Jays
 Share

Recommended Posts

Hey hello,

I started a new Project and also new in processwire.

So therefore sorry, if I ask a silly question, but I haven't found the answer in the documentation and here yet.

I want to great a Website in the following structure:

  • Section 1 = page section 1-1
    • page section 1-1
    • page section 1-2
    • page section 1-3
    • page section 1-4
  • Section 2 = page section 2-1
    • page section 2-1
    • page section 2-2
    • page section 2-3
    • page section 2-4
  • Section 3 = page section 3-1
    • page section 3-1
    • page section 3-2
    • page section 3-3
    • page section 3-4
  • Section 4 = page section 4-1
    • page section 4-1
    • page section 4-2
    • page section 4-3
    • page section 4-4

And each section should have the structure like in a slider Show - to go right (for the next page) or go left (for the previous page).

The order should be like I set it in the admin-area.

In which way and with which parameters can I create such a navigation, or how I get the Informationen about the next or previouse page?

 

It would be great to get some ideas!

thanks,

Jay

 

Link to comment
Share on other sites

Hi Robin S,

thanks for you anwser.

I tried it, but it doesn't work like this...

Next und Prev is moving on the  Level Section 1 - Section 2 - Section 3 - Section 4...

Over the Sections I have the "Home" entry...

Link to comment
Share on other sites

41 minutes ago, Jays said:

Next und Prev is moving on the  Level Section 1 - Section 2 - Section 3 - Section 4...

Yes, it navigates between sibling pages, so you would use it when you are on a child page of Section 1, Section 2, etc.

If you are on page Section 1 and you want to get the first child of that page you would use $page->child(). So if you want to navigate between levels as well as between siblings you would use some logic in your template to determine how you generate the navigation links. For example, check if $page has children and if so use $page->child(), otherwise use $page->next() - that sort of thing.

Edit: I just noticed this...

3 hours ago, Jays said:

Section 1 = page section 1-1

You can't have a page actually be another page (e.g. it's first child). Each page is an independent entity in the tree hierarchy. But you can have a page redirect to another page when it is viewed on the front-end. See $session->redirect().

  • Like 1
Link to comment
Share on other sites

To go a bit deeper in what Robin explained. When you are on the last page of a level, you want the first page of the next sibling of it's parent. For this to work, you have to be actually positioned on the child page, and not the parent — you can do that by redirecting to the first child when positioned on one of the parent pages. As for the next and prev links something like this should work to get the correct pages;

$prev = $page->prev->id ? $page->prev : $page->parent->prev->child;
$next = $page->next->id ? $page->next : $page->parent->next->child("sort=-sort");

 

  • Like 4
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...