Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /* ----------------------------------
- WIDGET: LIST SUB PAGES OR SIBLINGS
- IF HAS A PARENT WITH SUB PAGES.
- ---------------------------------- */
- class CAOASubPages extends WP_Widget {
- function CAOASubPages() {
- $options = array('classname' => 'widget-sub-pages', 'description' => 'Get a list of the sub pages from the current page.');
- parent::WP_Widget(false, $name = 'List Sub Pages of Current Page', $options);
- }
- function widget($args){
- global $post;
- extract($args);
- if($post->post_parent):
- $ancestors=get_post_ancestors($post->ID);
- $root=count($ancestors)-1;
- $postID = $ancestors[$root];
- else:
- $postID = $post->ID;
- endif;
- $wlp_args = array(
- 'child_of' => $postID,
- 'title_li' => __('<div class="title">'.get_the_title($post->post_parent).'</div>'),
- 'echo' => 0,
- );
- $wp_list_pages = wp_list_pages($wlp_args);
- if($wp_list_pages):
- print $before_widget;
- print '<ul>';
- print $wp_list_pages;
- print '</ul>';
- print $after_widget;
- endif;
- }
- }
- add_action('widgets_init', create_function('', 'return register_widget("CAOASubPages");'));
Advertisement
Add Comment
Please, Sign In to add comment