brewern

List Sub Pages Widget

Sep 28th, 2011
265
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 1.19 KB | None | 0 0
  1. /* ----------------------------------
  2.     WIDGET: LIST SUB PAGES OR SIBLINGS
  3.     IF HAS A PARENT WITH SUB PAGES.
  4. ---------------------------------- */
  5. class CAOASubPages extends WP_Widget {
  6.   function CAOASubPages() {
  7.     $options = array('classname' => 'widget-sub-pages', 'description' => 'Get a list of the sub pages from the current page.');
  8.     parent::WP_Widget(false, $name = 'List Sub Pages of Current Page', $options);
  9.   }
  10.  
  11.   function widget($args){
  12.     global $post;
  13.     extract($args);
  14.    
  15.     if($post->post_parent):
  16.       $ancestors=get_post_ancestors($post->ID);
  17.       $root=count($ancestors)-1;
  18.       $postID = $ancestors[$root];
  19.     else:
  20.       $postID = $post->ID;
  21.     endif;
  22.    
  23.     $wlp_args = array(
  24.       'child_of' => $postID,
  25.       'title_li' => __('<div class="title">'.get_the_title($post->post_parent).'</div>'),
  26.       'echo' => 0,
  27.     );
  28.     $wp_list_pages = wp_list_pages($wlp_args);
  29.    
  30.     if($wp_list_pages):
  31.       print $before_widget;
  32.       print '<ul>';
  33.       print $wp_list_pages;
  34.       print '</ul>';
  35.       print $after_widget;
  36.     endif;
  37.   }
  38. }
  39.  
  40. add_action('widgets_init', create_function('', 'return register_widget("CAOASubPages");'));
  41.  
Advertisement
Add Comment
Please, Sign In to add comment