Jump to content

How to determine whether page has any children


marcin
 Share

Recommended Posts

Hi Marcin,

The method you posted is one I hadn't thought of before, but it would certainly work just as well as any other. Another variation on it would be:

if($page->child()->id) {
   // has children 
} else {
   // does not have children
}

Here's the way that I usually do it. This is also what ProcessWire does before it executes the child() or children() methods, to decide whether a query should be executed:

if($page->numChildren) {
   // has children
} else {
   // doesn't have children
}
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...