Couldn’t you use the template tag, wp_list_pages(), along with the child_of and echo=0 parameters?
Didn’t test this, but something like:
if ( wp_list_pages('echo=0&child_of=' . post->ID) ) {
// the page has children
}
Are you wanting to see if the grandparent of the post is 77? Why not just check all the way?
$ancestors = get_post_ancestors($post);
if (in_array(77,$ancestors)) echo "77 is an ancestor of the post";
@otto42 you’re practically a magician! This works perfectly. Thank you very much!
@michaelh Your code works if I’m only testing for one ‘set’ of conditions. (See this over here.) Thanks for your help, though!
KS
(@karl19)
That bit of code from Otto42 works great, helped me limit the retrieved pages in a custom query. Thanks!
Hey MichalelH,
You look to be clever on this question. May i ask you a similar question?
I would like to have a menu with theses caracteristics:
– If the present page has a parent and no children, show a menu with its parent and him.
– If the present page has a parent and children, show a menu with its parent,him and its children.
– If the present page doesn’t have a parent (so it is a top level page), show a menu with its children only.
I have been stucking on it for ages.
Your help would be very appreciated.
Thx