Include Parent Page />
Include Parent Even With No Children/>
Pages to Exclude, Comma Separated:
Always Display Child Pages />
'; } #------------------------------------------------------------------------------------------------------------------------------ // this allows more than one instance function update( $new_instance, $old_instance ) { $instance = $old_instance; $instance['include_childless_parent'] = strip_tags($new_instance['include_childless_parent']); $instance['include_parent'] = strip_tags($new_instance['include_parent']); $instance['exclude'] = strip_tags($new_instance['exclude']); $instance['display_all'] = strip_tags($new_instance['display_all']); $instance['levels'] = strip_tags($new_instance['levels']); return $instance; } #------------------------------------------------------------------------------------------------------------------------- // This decides the name of the widget function advanced_sidebar_menu( ) { /* Widget settings. */ $widget_ops = array( 'classname' => 'sidebar-menu', 'description' => 'Creates a menu of all the pages using the child/parent relationship' ); /* Create the widget. */ $this->WP_Widget( 'advanced_sidebar_menu', 'Sidebar Menu', $widget_ops, $control_ops ); } #--------------------------------------------------------------------------------------------------------------------------- // adds the output to the widget area on the page function widget($args, $instance) { global $wpdb; global $p; global $post; #-- Create a usable array of the excluded pages $exclude = explode(',', $instance['exclude']); #-- if the post has parrents if($post->ancestors){ $parent = $wpdb->get_var( "SELECT post_parent from wp_posts WHERE ID=".$post->ID ); //--- If there is a parent of the post set $p to it and check if there is a parent as well while($parent != FALSE){ $p = $parent; $parent = $wpdb->get_var( "SELECT post_parent from wp_posts WHERE ID=".$parent); } } else { #--------- If this is the parent ------------------------------------------------ $p = $post->ID; } #-- Makes this work with all table prefixes #-- Added 1/22/12 global $table_prefix; $result = $wpdb->get_results( "SELECT ID FROM ".$table_prefix."posts WHERE post_parent = $p AND post_type='page' Order by menu_order" ); #---- if there are no children do not display the parent unless it is check to do so if($result != false || $instance['include_childless_parent'] == 'checked' ){ //Start the menu echo ''; } } #== /widget() } #== /Class