• 1.
    <?php function wpdev_156446_list_parent_page_tree() {
  • 2.
     
  • 3.
        if ( ! is_page() ) {
  • 4.
            return;
  • 5.
        }
  • 6.
     //parent variables
  • 7.
        $parent = get_post($post->post_parent);
  • 8.
        $parent_title = get_the_title($parent);
  • 9.
        $grandparent = $parent->post_parent;
  • 10.
        $grandparent_title = get_the_title($grandparent);
  • 11.
        $current_page_parent = ( $post->post_parent ? $post->post_parent : $post->ID );
  • 12.
     
  • 13.
     // is the homepage the granparent? = third level page
  • 14.
    if ($grandparent == is_page('0')) {
  • 15.
        $children = wp_list_pages("title_li=&include=".$post->post_parent."&echo=0"); // list the parent page
  • 16.
        $children .= wp_list_pages("title_li=&child_of=".$post->post_parent."&echo=0"); // append the list of children pages to the same $children variable
  • 17.
        if ($children) { ?>
  • 18.
        <ul class="submenu">
  • 19.
          echo $children; /*print list of pages*/
  • 20.
        </ul>
  • 21.
     
  • 22.
     // is the homepage the parent? = second level page
  • 23.
        } elseif ($post->post_parent ==is_page('0')) {
  • 24.
          $children = wp_list_pages('title_li=&child_of='.$post->ID.'&echo=0');
  • 25.
      if ($children) { 
  • 26.
     
  • 27.
        <ul>
  • 28.
          <li class="current_page_item"><?php echo get_the_title(); ?></li>
  • 29.
          echo $children;
  • 30.
        </ul>
  • 31.
     
  • 32.
        } else {// your else stuff
  • 33.
     
  • 34.
        }
  • 35.
     
  • 36.
     
  • 37.
    } ?>
  • 38.
     
<?php function wpdev_156446_list_parent_page_tree() { if ( ! is_page() ) { return; } //parent variables $parent = get_post($post->post_parent); $parent_title = get_the_title($parent); $grandparent = $parent->post_parent; $grandparent_title = get_the_title($grandparent); $current_page_parent = ( $post->post_parent ? $post->post_parent : $post->ID ); // is the homepage the granparent? = third level page if ($grandparent == is_page('0')) { $children = wp_list_pages("title_li=&include=".$post->post_parent."&echo=0"); // list the parent page $children .= wp_list_pages("title_li=&child_of=".$post->post_parent."&echo=0"); // append the list of children pages to the same $children variable if ($children) { ?> <ul class="submenu"> echo $children; /*print list of pages*/ </ul> // is the homepage the parent? = second level page } elseif ($post->post_parent ==is_page('0')) { $children = wp_list_pages('title_li=&child_of='.$post->ID.'&echo=0'); if ($children) { <ul> <li class="current_page_item"><?php echo get_the_title(); ?></li> echo $children; </ul> } else {// your else stuff } } ?>

Copy Code to Clipboard Raw

Sign-in or Create a Free Account.

Snippi uses Twitter or Facebook to register and create accounts. Registration will enable you to keep track of your snippets. We never spam your timeline or wall. Ever.

Sign-in with Facebook Sign-in with Twitter