Title
Include Parent Page: />
Include Parent Even With No Children: />
Use Built in Styling: />
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']); $instance['css'] = strip_tags($new_instance['css']); $instance['title'] = strip_tags($new_instance['title']); return $instance; } #------------------------------------------------------------------------------------------------------------------------- // This decides the name of the widget function advanced_sidebar_menu_page( ) { /* Widget settings. */ $widget_ops = array( 'classname' => 'advanced-sidebar-menu', 'description' => 'Creates a menu of all the pages using the child/parent relationship' ); $control_ops = array( 'width' => 290 ); /* Create the widget. */ $this->WP_Widget( 'advanced_sidebar_menu', 'Advanced Sidebar Pages Menu', $widget_ops, $control_ops); } #--------------------------------------------------------------------------------------------------------------------------- /** * Outputs the page list * @see WP_Widget::widget() * * @uses for custom post types send the type to the filter titled 'advanced_sidebar_menu_post_type' * @uses change the top parent manually with the filter 'advanced_sidebar_menu_top_parent' * @uses change the order of the 2nd level pages with 'advanced_sidebar_menu_order_by' filter * * @since 3.6.13 */ function widget($args, $instance) { global $wpdb, $post, $table_prefix; $asm = new advancedSidebarMenu; extract($args); //Filter this one with a 'single' for a custom post type will default to working for pages only $post_type = apply_filters('advanced_sidebar_menu_post_type', 'page' ); if( $post_type != 'page' ){ add_filter('page_css_class', array( $asm, 'custom_post_type_css'), 2, 4 ); } #-- Create a usable array of the excluded pages $exclude = explode(',', $instance['exclude']); #-- if the post has parents if($post->ancestors){ $top_parent = end( $post->ancestors ); } else { #--------- If this is the parent ------------------------------------------------ $top_parent = $post->ID; } //Filter for specifying the top parent $top_parent = apply_filters('advanced_sidebar_menu_top_parent', $top_parent, $post ); //Filter for specifiying the order by $order_by = apply_filters('advanced_sidebar_menu_order_by', 'menu_order', $post ); /** * Must be done this way to prevent doubling up of pages */ $child_pages = $wpdb->get_results( "SELECT ID FROM ". $wpdb->posts ." WHERE post_parent = $top_parent AND post_status='publish' AND post_type='$post_type' Order by $order_by" ); //for depreciation $p = $top_parent; $result = $child_pages; #---- if there are no children do not display the parent unless it is check to do so if( ($child_pages) || (($instance['include_childless_parent'] == 'checked') && (!in_array($top_parent, $exclude)) ) ){ if( $instance['css'] == 'checked' ){ echo ''; } //Start the menu echo $before_widget; $asm->set_widget_vars( $instance, $top_parent, $exclude ); #-- Bring in the view require( $asm->file_hyercy( 'page_list.php' ) ); echo $after_widget; } } #== /widget() } #== /Clas