Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- $pages = get_pages( array(
- 'sort_column' => 'menu_order',
- 'parent' => 0)
- );
- ?>
- <?php $ancestor = get_ancestors($post->ID,'page');
- if ($ancestor[1])
- //I am a subsubpage
- $id = array_pop($ancestor);
- elseif ($post->post_parent)
- //I am a subpage
- $id = $post->post_parent;
- else
- //I am a page
- $id = $post->ID;
- $subpages = get_pages(array("child_of"=>$id,"parent"=>$id));
- ?>
- <?php foreach ($pages as $page):?>
- <li>
- <a href="<?php echo get_permalink($page->ID); ?> "><?php echo $page->post_title; ?></a>
- <?php
- if ( $id == $page->ID ): //simplified
- ?>
- <ul>
- <?php
- foreach($subpages as $subpage):
- ?>
- <li>
- <a href="<?php echo get_permalink($subpage->ID); ?> "><?php echo $subpage->post_title ?></a>
- <?php
- $subsubpages = get_pages(array("child_of"=>$subpage->ID,"parent"=>$subpage->ID)); //hierarchical sub-sub-level
- if ( $subsubpages ):
- ?>
- <ul>
- <?php
- foreach($subsubpages as $subsubpage):
- ?>
- <li>
- <a href="<?php echo get_permalink($subsubpage->ID); ?> "><?php echo $subsubpage->post_title ?></a>
- </li>
- <?php endforeach; ?>
- </ul>
- <?php endif; ?>
- </li>
- <?php endforeach; ?>
- </ul>
- <?php endif; ?>
- </li>
- <?php endforeach;?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement