Jump to content

Exclude pages with unpublished parent


thomas.isberg
 Share

Recommended Posts

The only way I see to do this in a find with a selector, is to do something like this:


$up_pages = $pages->find("status=unpublished");
$sel = '';
foreach($up_pages as $p){
   $sel .= ",has_parent!=$p->id";
}
$pa = $pages->find("template=basic-page$sel");

foreach($pa as $p){
   echo "<p>page: $p->title $p->url</p>";
}

  • Like 3
Link to comment
Share on other sites

Maybe it would be a good idea to create a new method to find pages Starting in the homepage and running the branches from there, would this be possible? Like this we could do this kind of filtering very easily.

Link to comment
Share on other sites

The simplest way would be just to post-filter them after your search. Meaning, whatever code you have outputting the found pages would just check the status and skip over any that had unpublished parents.

foreach($items as $item) {
 $skip = false;
 foreach($item->parents as $parent) if($parent->is(Page::statusUnpublished)) $skip = true; 
 if($skip) continue;
 // otherwise item is good to output
 echo "<li>$item->title</li>";
}

But if you are also working with pagination, then you kind of need to have these things filtered ahead of time. In that case, I think Soma's method would be good. The hope is that you don't have too many unpublished pages to be found, that could slow the query. One way to further optimize that would be to find only unpublished pages that have children.

$up_pages = $pages->find("status=unpublished, numChildren>0"); 
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...