joe_g Posted August 19, 2013 Share Posted August 19, 2013 Hi, how can i get the top level of a certain template? Something like $page->parentMost('template=thing'); perhaps. Or, How can I get the top level page under a certain page. I'm looking for rootParent, but relative to a page..? Like $page->topMost($aTopLevelPage); .. or something.. thanks for any ideas, J Link to comment Share on other sites More sharing options...
arjen Posted August 20, 2013 Share Posted August 20, 2013 Top level page $page->rootParent Top level pages of a template $pages->find("template=thing, parent=1") // 1 is the ID of the homepage, so a child will automatically be the top level page 2 Link to comment Share on other sites More sharing options...
joe_g Posted August 20, 2013 Author Share Posted August 20, 2013 Thanks, – but rootParent is absolute to the root AFAIK. What I'm looking for is the topmost page right under an arbitrary page. "The top most parent page under page X". – In your other answer, how do I know what page is the top-most page of the resulting parents? /J Link to comment Share on other sites More sharing options...
Soma Posted August 20, 2013 Share Posted August 20, 2013 $page->parents("template=thing"); $page->parent("template=thing"); Look cheat sheet for reference. But then I don't understand at all what exactly you looking for. Link to comment Share on other sites More sharing options...
kongondo Posted August 20, 2013 Share Posted August 20, 2013 Just so we are on the same page understand each other Home About Mission History 1800 1900 2000 rootParent of About = About rootParent of Mission = Mission rootParent of History = History rootParent of 1800, 1900, 2000 = History $page->parent of About, Mission, History = Home $page->parent of 1800, 1900, 2000 = History $page->parents of About, Mission, History = Home $page->parents of 1800, 1900, 2000 = History, Home 2 Link to comment Share on other sites More sharing options...
adrian Posted August 20, 2013 Share Posted August 20, 2013 "What I'm looking for is the topmost page right under an arbitrary page. "The top most parent page under page X". Thanks, – but rootParent is absolute to the root AFAIK. What I'm looking for is the topmost page right under an arbitrary page. "The top most parent page under page X". – In your other answer, how do I know what page is the top-most page of the resulting parents? /J That sounds to me like you are looking for the first child of an arbitrary page - is that right? 1 Link to comment Share on other sites More sharing options...
Soma Posted August 20, 2013 Share Posted August 20, 2013 If that's right it would the the first child or the first child that has children? Not sure. But he's speaking of a "parent"? So this would be easy with $page->child("template=xy, children.count>0"); To get the first child of a page: $page->child() will give you the first child with regarding to the sorting. $page->child("template=sowieso") same as $page->children("template=xy")->first(); 2 Link to comment Share on other sites More sharing options...
joe_g Posted August 21, 2013 Author Share Posted August 21, 2013 Sorry for the confusion, What I'm looking for is how to get the top event (Event3) from Sub-sub-event2. All levels underneath Events are the same template, 'event'. I cant use rootParent, because that points to Events. If I use parents, how do i know what of the event is the top-most in the result, if they're all the same template? (Side-note: How fast is parents(), does it recurse upwards for every step, or is it done in one call somehow?) thanks! Home Events Event1 Event2 Event3 Sub-event1 Sub-event2 Sub-event3 Sub-sub-event1 Sub-sub-event2 Link to comment Share on other sites More sharing options...
kongondo Posted August 21, 2013 Share Posted August 21, 2013 echo $page->parent->parent->title; works just fine Link to comment Share on other sites More sharing options...
joe_g Posted August 21, 2013 Author Share Posted August 21, 2013 thanks kongondo, but I don't know how many parents are the current page/event. I don't know how many ->parents I would have to put. I realise I can 1. get ->parents() 2. loop through each result and count(parents) on each one but this seems slow, I was hoping there was a fast way, similar to rootParent, that is only one call, somehow... Link to comment Share on other sites More sharing options...
kongondo Posted August 21, 2013 Share Posted August 21, 2013 So are you saying you don't know how many levels deep your events will be going? From your example I assumed you wanted the grand-parent...Edit: ...but I don't know how many parents are the current page/event. I don't get this bit "how many parents are the current page/event". Since current page/event cannot be its own parent, did you mean to say.. "how many parents (recursively) the current page/event will have"? Link to comment Share on other sites More sharing options...
joe_g Posted August 21, 2013 Author Share Posted August 21, 2013 ehm, ....this was maybe a bit too easy. Maybe that's why it was confusing ;P But the result seems to be in order of hiearchy, meaning the first result of parents() = top-most it doesn't mention it in the cheat sheet, but i guess i can count on the order to be a good way to know the top-most page? Link to comment Share on other sites More sharing options...
kongondo Posted August 21, 2013 Share Posted August 21, 2013 I'm not sure I follow to be honest. Did you find a solution? As you were typing, I tried to think this out logically...technically, what you want is the child (Event3) of the rootParent (Events) who (the child) is a parent/grand-parent, (has_parent) etc of the sub-events under Event3 Getting that logic in a selector..... Edit: Kind related...but about downward ancestry.. http://processwire.com/talk/topic/956-how-to-get-grand-childs/ Link to comment Share on other sites More sharing options...
joe_g Posted August 22, 2013 Author Share Posted August 22, 2013 I was trying to get the top-event (Event3) from Sub-sub-event2 (or sub-event3, or sub-sub-sub-sub-sub-eventx). I guess the solution is simply ->parents('template=event')->first(); J 1 Link to comment Share on other sites More sharing options...
kongondo Posted August 22, 2013 Share Posted August 22, 2013 Glad you got it sorted Joe. As you rightly suggest, key here is to make sure "Home" and "Event" do not share the same template. Otherwise the code would return home as the first parent. You may wish to mark this as solved (you answered your own question ) 1 Link to comment Share on other sites More sharing options...
interrobang Posted August 22, 2013 Share Posted August 22, 2013 Glad you got it sorted Joe. As you rightly suggest, key here is to make sure "Home" and "Event" do not share the same template. Otherwise the code would return home as the first parent. If your Home has the same template as your events you can use this selector: $parentmost = $page->parents("parent={$page->rootParent}")->first(); 2 Link to comment Share on other sites More sharing options...
Soma Posted August 22, 2013 Share Posted August 22, 2013 If Events all have the same template it would be If your Home has the same template as your events you can use this selector: $parentmost = $page->parents("parent={$page->rootParent}")->first(); Which would be the same as $parentmost = $page->parents->eq(2); or $parentmost = $page->parents[1]; 2 Link to comment Share on other sites More sharing options...
kongondo Posted August 22, 2013 Share Posted August 22, 2013 Bookmarked! Thanks guys... Please remind me what eq does? Googling a two-letter word can be tricky, thanks Link to comment Share on other sites More sharing options...
Soma Posted August 22, 2013 Share Posted August 22, 2013 Bookmarked! Thanks guys... Please remind me what eq does? Googling a two-letter word can be tricky, thanks Look no further http://cheatsheet.processwire.com/?filter=eq Link to comment Share on other sites More sharing options...
kongondo Posted August 22, 2013 Share Posted August 22, 2013 Facepalm; of course, the C.sheet! Thanks Soma... 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