WordPress.org

Ready to get started?Download WordPress

Forums

List parents and child pages of curent child page (5 posts)

  1. ul71m0
    Member
    Posted 1 year ago #

    Ok after I spent whole morning trying and testing various stuff I came here to cry for help. This is my situation

    Level 1
      -level 2
      -level 2
      -level 2
         -level 3
         -level 3
         -level 3
      -level 2
    Level 1
    Level 1

    Ok I want when I`m on level 3 pages to list all level 3 and level 2 pages from same level 1 parent.

    I tried with this but no luck:

    <?php
                        $output = wp_list_pages('echo=0&depth=1&title_li=');
                        if (is_page()) {
                            $page = $post->ID;
                            if ($post->post_parent) {
                                $page = $post->post_parent;
                            }
                            $children = wp_list_pages('echo=0&child_of=' . $page . '&title_li=');
                            if ($children) {
                                $output = wp_list_pages('echo=0&child_of=' . $page . '&title_li=');
                            }
                        }
                        echo $output;
                        ?>
  2. rikardo85
    Member
    Posted 1 year ago #

    try:

    <?php
      if($post->post_parent)
      $children = wp_list_pages("title_li=&child_of=".$post->post_parent."&echo=0");
      else
      $children = wp_list_pages("title_li=&child_of=".$post->ID."&echo=0");
      if ($children) { ?>
      <ul>
      <?php echo $children; ?>
      </ul>
      <?php } ?>
  3. ul71m0
    Member
    Posted 1 year ago #

    That gives me just level 3 ones, not level 2.

  4. ul71m0
    Member
    Posted 1 year ago #

  5. rikardo85
    Member
    Posted 1 year ago #

    Of course! I have used this on a few of my sites.

    Its a great plugin.

Topic Closed

This topic has been closed to new replies.

About this Topic