Co-Founder of Tradeomics. Interactive Designer & Developer @CJRWinteractive. Husband. Father of a beautiful 3 yr old girl.
@brewernA collection of code, insight, tips & tricks. Mostly on design, jQuery, WordPress, Drupal, Rails, & the occasional random thought.
A WordPress widget to list the sub-pages of the current page or the siblings if the current page is a sub-page.
Get the code from http://pastebin.com/2MxHfvx1 and place this code within functions.php which is in your theme folder.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 | /* ---------------------------------- 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> <ul>';</ul> </ul> <ul> <ul>print $wp_list_pages;</ul> </ul> <ul>print '</ul> '; print $after_widget; endif; } } add_action('widgets_init', create_function('', 'return register_widget("CAOASubPages");')); |