'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); } /** * Output a simple widget Form * Not of ton of options here but who need them * Most of the magic happens automatically * * @since 4.7.13 */ function form( $instance ) { ?>
Title
Include Parent Page: />
Include Parent Even With No Children: />
Use this Plugin's Styling: />
Pages to Exclude, Comma Separated:
Legacy Mode: (use pre 4.0 structure and css) />
Always Display Child Pages: />
'; } /** * Handles the saving of the widget * * @since 4.5.13 */ function update( $new_instance, $old_instance ) { $new_instance['exclude'] = strip_tags($new_instance['exclude']); return $new_instance; } #--------------------------------------------------------------------------------------------------------------------------- /** * 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 * * @filter apply_filters('advanced_sidebar_menu_page_widget_output',$content, $args, $instance ); * apply_filters('advanced_sidebar_menu_order_by', 'menu_order', $post, $args, $instance ); * apply_filters('advanced_sidebar_menu_top_parent', $top_parent, $post, $args, $instance ); * apply_filters('advanced_sidebar_menu_post_type', 'page', $args, $instance ); * * * @since 4.7.13 */ function widget($args, $instance) { global $wpdb, $post, $table_prefix; //There will be no pages to generate on an archive page if( is_archive() ) return; $asm = new advancedSidebarMenu; $asm->instance = $instance; $asm->args = $args; 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', $args, $instance ); $asm->post_type = $post_type; 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']); $asm->exclude = $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, $args, $instance ); $asm->top_id = $top_parent; //Filter for specifiying the order by $order_by = apply_filters('advanced_sidebar_menu_order_by', 'menu_order', $post, $args, $instance ); $asm->order_by = $order_by; /** * 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)) ) ){ $legacy = isset( $instance['legacy_mode'] ); if( $instance['css'] == 'checked' ){ echo ''; } //Start the menu echo $before_widget; #-- Bring in the require( $asm->file_hyercy( 'page_list.php', $legacy ) ); echo apply_filters('advanced_sidebar_menu_page_widget_output',$content, $args, $instance ); echo $after_widget; } } #== /widget() } #== /Clas