WordPress.org

Ready to get started?Download WordPress

Forums

[resolved] Check if page has parent and childs (2 posts)

  1. Mattz
    Member
    Posted 6 years ago #

    I'm figuring out using wp_list_pages() if it's possible to check if the page where I'm at has a parent and childs.

    I would like to make something that when it has a parent and childs that it only shows the childpages using wp_list_pages.

    Another example that I was trying to find is in this case that if the page does not have a child that the wp_list_pages only shows the parent of the page.

    So, I'm actually trying to find two if statements where I couldn't get them working.

    Should this be possible ?

  2. Mattz
    Member
    Posted 6 years ago #

    It seems that I have a real issue here.

    I have a parent with 3 childs under it. Every child has about 5 childs:

    • Parent
      • Child_1
        • Child
        • Child
        • Child
        • Child
      • Child_2
        • Child
        • Child
        • Child
        • Child
      • Child_3
        • Child
        • Child
        • Child
        • Child

      I'm able to show the Childs of

      • 1 when I'm on one of the childs of
      • 1, this using:

      wp_list_pages( 'echo=0&child_of=' . $post->ID . '&depth=1&title_li=' );

      But when I go to Child_2 or Child3, I only get 2 of the Child_X to show when I use this in a if:

      wp_list_pages("title_li=&child_of=".$post->post_parent."&exclude=".$post->ID."&echo=0&depth=1");

      Which is not nice because it should display the Childs of Child_2 and Child_3.

      So when I visit Child_1 I see his childs in the menu, and when I go to Child_2 I see Child_1 and Child_3 in the menu, the same for Child_3 where I only see Child_1 and Child_2 and not his own childs.

      Is this difficult to build or almost impossible ?

Topic Closed

This topic has been closed to new replies.

About this Topic