Testing specific page ID for child pages
Permalink 1 user found helpful
Hi Guys
I am hard coding in a dropdown navigation and for each link I want to test if it has child elements so I can add in the dropdown menu and display the child links.
I've got the displaying child links worked out. What I can't quite grasp is how I can say 'here's a page ID, does it have children?'.
I have been tring this method:
But I can't seem to find anyway to pass it an ID and the documentation is sparse.
Can any clever souls suggest a way of doing this?
thanks drongo (falling asleep at his desk :/ )
I am hard coding in a dropdown navigation and for each link I want to test if it has child elements so I can add in the dropdown menu and display the child links.
I've got the displaying child links worked out. What I can't quite grasp is how I can say 'here's a page ID, does it have children?'.
I have been tring this method:
$page->getNumChildren()
But I can't seem to find anyway to pass it an ID and the documentation is sparse.
Can any clever souls suggest a way of doing this?
thanks drongo (falling asleep at his desk :/ )
Hi mhawk
Thanks for getting back to me. I still remember how u solved my last issue :).
I am not sure the above would work as I need to set the dropdown even if the user is not on the current page.
So what I was hoping for was a method that would return the number of child pages based on whatever page id I supply.
Thanks for getting back to me. I still remember how u solved my last issue :).
I am not sure the above would work as I need to set the dropdown even if the user is not on the current page.
So what I was hoping for was a method that would return the number of child pages based on whatever page id I supply.
Sorry, I misunderstood. Try this instead:
$cid = 1; //cID of home page, for example. $p = Page::getByID($cid); echo $p->getNumChildrenDirect();
Thank you mhawke.
That's precisely what I needed and it worked perfectly. You are my saviour once again :)
That's precisely what I needed and it worked perfectly. You are my saviour once again :)
or this: