Jump to content

rootParent selector?


adrian
 Share

Recommended Posts

I was hoping there would be a selector called rootParent. I ended up getting all the pages that matched the rest of my selectors and then filtered them out with $page->rootParent in the foreach loop. This isn't a bad option, but causes problems when using limit in the initial selector set.

Anyway, just wondering if there is a better way to do this, or if rootParent could be added as a selector. Maybe the template selector is a cleaner solution in most cases?

Link to comment
Share on other sites

Yep, that would do it. I am still not quite always thinking in PW yet :)

I was initially setting it up as: $latest = $pages->find("rootParent=xxx, sort=-modified, limit=10"), but in reality I want to specify more than one rootParent, so I would need the ability for "get" or "find"ing more than one anyway, which isn't possible - correct?

Link to comment
Share on other sites

Replace id and id2 with actual numbers in Soma's example. You can get the page numbers in the admin by clicking on a page name and clicking the edit button - their ID will be clear in the URL.

Link to comment
Share on other sites

Hey Pete - yep, I was using proper page ID numbers. I actually just tested out a has_parent using the selector test tool, with multiple pipe-separated page IDs and found that it returns every page in my system including all admin/system pages. Each of the individual page IDs on their own work as expected.

Link to comment
Share on other sites

Yes sorry, I forgot about it that it works only for 1 parent! Too many things in my head lately :)

However, maybe you can use "parent=id|id2|id3" if it only for direct children pages.

Maybe you can tell a little more about what you want to archive, I'm sure there's a good solution.

Link to comment
Share on other sites

Hi Soma - no worries - I know how you feel :)

Basically what I am doing is creating a custom RSS feed and latest activity widget, but I only want to highlight details from certain sections of the site. I have some user edited pages, a user edited glossary, and a forum. These are the three parent pages. 

I ended up going with this which is a little ugly, but does the trick:

$latest = $pages->find("sort=-modified, limit=30");

$items = new PageArray;

foreach($latest as $lpage){
    if(($lpage->rootParent=='1130' || $lpage->rootParent=='1192' || $lpage->rootParent=='1021') && ($lpage!='1130' && $lpage!='1192' && $lpage!='1021')){
        $items->add($lpage);
    }
}
 

I actually might end up switching to a template selector as I think this will be cleaner and still achieve what I need. 

  • Like 1
Link to comment
Share on other sites

  • 8 years later...
41 minutes ago, adrian said:

It looks like has_parent now supports multiple pages and I think it has served all my needs around this. What can't it do in your use case?

Totally did not think of that one. Thanks a ton!

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...