Fuzzy Posted March 4, 2020 Share Posted March 4, 2020 Hi, is there a possibility to check if a page is before/after another page in the admin page tree? Example: > Categories >> In Progress >> Completed >> Waiting for Approval What I'm looking for is an if statement that checks whether "Completed" is before/after "In Progress" in the page tree. Checking the ID is not an option as "In Progress" might have been created after "Completed". Thanks in advance for your help! Link to comment Share on other sites More sharing options...
MoritzLost Posted March 4, 2020 Share Posted March 4, 2020 You can check $page->prev() and $page->next() to find siblings matching a selector. You need of course some criteria to identify the "Completed" page – if using an ID is not an option, you could use the name or title of the page. Here are some code examples (those assume $page is the "In Progress" page): // will be true if the "Completed" page is somewhere before the current $page $CompletedIsBefore = $page->prev('title="Completed"')->id !== 0; // will be true if the "Completed" page is somewhere after the current $page $CompletedIsAfter = $page->next('title="Completed"')->id !== 0; // will be true if the "Completed" page comes directly before the current $page $CompletedIsPreviousPage = $page->prev()->matches('title="Completed"'); See $page->prev() and $page->next() in the API reference. 1 Link to comment Share on other sites More sharing options...
Robin S Posted March 4, 2020 Share Posted March 4, 2020 So long as you don't have a custom sort setting on the parent template or parent page (i.e. the pages are just sorted according to the default which is "Manual drag-n-drop") then you can compare the "sort" value of the pages. if($sibling_1->sort > $sibling_2->sort) { // $sibling_1 is after $sibling_2 in the page tree } 1 Link to comment Share on other sites More sharing options...
Fuzzy Posted March 4, 2020 Author Share Posted March 4, 2020 Thanks to both of you, @MoritzLost and @Robin S. In my case Robin's idea did the trick ? 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