Advertisement
alchymyth

page navi

Jul 31st, 2011
228
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 1.29 KB | None | 0 0
  1. <?php
  2.     $pages = get_pages( array(
  3.                 'sort_column' => 'menu_order',
  4.                 'parent' => 0)
  5.                 );
  6.     ?>
  7.  
  8.     <?php $ancestor = get_ancestors($post->ID,'page');
  9.         if ($ancestor[1])
  10.             //I am a subsubpage
  11.             $id = array_pop($ancestor);
  12.         elseif ($post->post_parent)
  13.             //I am a subpage
  14.             $id = $post->post_parent;
  15.         else
  16.             //I am a page
  17.             $id = $post->ID;
  18.  
  19.         $subpages = get_pages(array("child_of"=>$id,"parent"=>$id));
  20.     ?>
  21.  
  22. <?php foreach ($pages as $page):?>
  23.     <li>
  24.  
  25.         <a href="<?php echo get_permalink($page->ID); ?> "><?php echo $page->post_title; ?></a>
  26.         <?php
  27.         if ( $id == $page->ID ): //simplified  
  28.  
  29.         ?>
  30.         <ul>
  31.             <?php
  32.                 foreach($subpages as $subpage):
  33.             ?>
  34.             <li>
  35.                 <a href="<?php echo get_permalink($subpage->ID); ?> "><?php echo $subpage->post_title ?></a>
  36.             <?php
  37.            
  38.         $subsubpages = get_pages(array("child_of"=>$subpage->ID,"parent"=>$subpage->ID)); //hierarchical sub-sub-level
  39.         if ( $subsubpages ):
  40.        
  41.         ?>
  42.         <ul>
  43.             <?php
  44.                 foreach($subsubpages as $subsubpage):
  45.             ?>
  46.             <li>
  47.                 <a href="<?php echo get_permalink($subsubpage->ID); ?> "><?php echo $subsubpage->post_title ?></a>
  48.             </li>
  49.            
  50.  
  51.             <?php endforeach; ?>
  52.         </ul>
  53.         <?php endif; ?>
  54.             </li>
  55.            
  56.  
  57.             <?php endforeach; ?>
  58.         </ul>
  59.         <?php endif; ?>
  60.     </li>
  61.  
  62. <?php endforeach;?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement