Load_TextDomain(); // Setup the Widget data $this->WP_Widget ( False, $this->t('Sub pages'), Array('description' => $this->t('You can add this widget to sidebars on pages to show all sub pages of the current one.'))); // Register as Widget Add_Action ('widgets_init', Array($this, 'Register')); } Function Register(){ Register_Widget(get_class($this)); } Function Load_TextDomain(){ $this->text_domain = get_class($this); load_textdomain ($this->text_domain, DirName(__FILE__).'/language/'.get_locale().'.mo'); } Function t ($text, $context = ''){ // Translates the string $text If ($context == '') return __($text, $this->text_domain); Else return _x($text, $context, $this->text_domain); } Function widget ($widget_args, $settings){ // if this isn't a page we bail out. If ( !is_page() ) return False; Global $post; If ($post->post_parent != 0) $parent = get_post($post->post_parent); Else $parent = False; // predefine settings $settings = Array_Merge( Array( 'title' => $this->t('Navigation'), 'sortby' => 'menu_order, post_title', 'exclude' => '' ), $settings ); // Default Args for selecting sub pages $page_args = Array( 'title_li' => '', 'child_of' => $post->ID, 'sort_column' => $settings['sortby'], 'exclude' => $settings['exclude'], 'depth' => 1, 'echo' => False ); If ($page_listing = wp_list_pages($page_args)){ // There are some sub pages If ($settings['replace_widget_title']) $settings['title'] = $post->post_title; } Else { // there are no sub pages we try to show all pages in the same depth level. $page_args['child_of'] = ($parent ? $parent->ID : 0); // If the parent page is a real page its title will be our widget title If ($parent && $settings['replace_widget_title']) $settings['title'] = $parent->post_title; // Read the subpages again $page_listing = wp_list_pages($page_args); } // if there are no sub pages we bail out. If ( !$page_listing ) return False; // Widget output Echo $widget_args['before_widget']; // Widget title If (!$settings['hide_widget_title']) Echo $widget_args['before_title'] . $settings['title'] . $widget_args['after_title']; // output Page listing Echo ''; // Widget bottom Echo $widget_args['after_widget']; } Function form ($settings){ // Show Form: ?>

t('Title:'); ?>

/> t('Hide the widget title.') ?>

/> t('Replace the widget title with the title of the parent page if possible.') ?>


/> t('Hide link to parant page.') ?>