• Resolved Ricky Irvine

    (@dressedinvalue)


    I have $post->post_parent=="77" checking to see if the current page is a child of the page id 77. Is there a way to check if the current page is another level deep (sub-sub-page)?

Viewing 6 replies - 1 through 6 (of 6 total)
  • 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
    }
    Moderator Samuel Wood (Otto)

    (@otto42)

    WordPress.org Admin

    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";
    Thread Starter Ricky Irvine

    (@dressedinvalue)

    @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!

    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

    Ryan

    (@daobydesign)

    @otto42: Fantastic. Just fantastic.

    That really should be added to the page in the Codex dealing with creating sub-page conditionals.

Viewing 6 replies - 1 through 6 (of 6 total)
  • The topic ‘Depth of $post->post_parent’ is closed to new replies.