Pastebin launched a little side project called VERYVIRAL.com, check it out ;-) Want more features on Pastebin? Sign Up, it's FREE!
Guest

Untitled

By: a guest on Jun 12th, 2012  |  syntax: None  |  size: 0.82 KB  |  views: 64  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  1. // Generate page tree
  2. function purplepastels_page_tree($this_page) {
  3.         $pagelist = '';
  4.         if( !$this_page->post_parent ) {
  5.                 $children = wp_list_pages('title_li=&child_of='.$this_page->ID.'&echo=0');
  6.                 if( $children ) {
  7.                         $pagelist .= '<li class="current_page_item"><a href="'.  get_page_link($this_page->ID) .'">' . $this_page->post_title . '</a>';
  8.                         $pagelist .= '<ul>' . $children . '</ul>';
  9.                         $pagelist .= '</li>';
  10.                 }
  11.         }
  12.         elseif( $this_page->ancestors ) {
  13.                 // get the top ID of this page. Page ids DESC so top level ID is the last one
  14.                 $ancestor = end($this_page->ancestors);
  15.                 $pagelist .= wp_list_pages('title_li=&include='.$ancestor.'&echo=0');
  16.                 $pagelist = str_replace('</li>', '', $pagelist);
  17.                 $pagelist .= '<ul>' . wp_list_pages('title_li=&child_of='.$ancestor.'&echo=0') .'</ul></li>';
  18.         }
  19.         return $pagelist;
  20. }