Sinmok Posted January 29, 2014 Share Posted January 29, 2014 Hello all, Probably a silly question..but I'm having trouble figuring out if a page is a descendant of another page. Let's assume I've got a page currently referenced as $section. I need to know whether $page (current page) is a descendant of $section, preferably returning a true/false value. Does anyone know how to accomplish this? Something like this would be solid: if($page->isDescendant($section)){ //$page is a descendant of the $section node } //OR if($section->hasDescendant($page)){ //$section is an ancestor of $page { EDIT: In the end, I got it working using the following code. $page->parents("id=$section->id")->first()->id == $section->id This is probably not the best of solutions though so I'm interested in hearing yours. Cheers Link to comment Share on other sites More sharing options...
kongondo Posted January 29, 2014 Share Posted January 29, 2014 has_parent.... http://processwire.com/api/selectors/ http://cheatsheet.processwire.com/ 1 Link to comment Share on other sites More sharing options...
Sinmok Posted January 29, 2014 Author Share Posted January 29, 2014 An example would be helpful, as I can't get a working solution with has_parent within find(). Link to comment Share on other sites More sharing options...
Soma Posted January 29, 2014 Share Posted January 29, 2014 My take if($page->parents->has($section)) ... if($section->find("id=$page")->count()) ... // direct parent-child if($section->children("id=$page")->count()) ... if($page->parent === $section) ... 5 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