Title
Include Parent Category />
Include Parent Even With No Children />
Use Built in Styling />
Display Categories on Single Posts />
Categories to Exclude, Comma Separated:
Always Display Child Categories />
'; } #------------------------------------------------------------------------------------------------------------------------------ // 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['single'] = strip_tags($new_instance['single']); //Display on single pages $instance['new_widget'] = strip_tags($new_instance['new_widget']); //Create a new widget for each single category $instance['title'] = strip_tags($new_instance['title']); return $instance; } #------------------------------------------------------------------------------------------------------------------------- // This decides the name of the widget function advanced_sidebar_menu_category( ) { /* Widget settings. */ $widget_ops = array( 'classname' => 'sidebar-menu-category', 'description' => 'Creates a menu of all the Categories using the child/parent relationship' ); $control_ops = array( 'width' => 290 ); /* Create the widget. */ $this->WP_Widget( 'advanced_sidebar_menu_category', 'Advanced Sidebar Categories Menu', $widget_ops, $control_ops ); } #--------------------------------------------------------------------------------------------------------------------------- // adds the output to the widget area on the page function widget($args, $instance) { global $asm; #-- Create a usable array of the excluded pages $exclude = explode(',', $instance['exclude']); $cat_ids = $already_top = array(); $asm_once = $asm_cat_widget_count = false; //keeps track of how many widgets this created $count = null; //If on a single page create an array of each category and create a list for each if( is_single() && ($instance['single'] == 'checked') ){ $category_array = get_the_category(); foreach( get_the_category() as $id => $cat ){ $cat_ids[] = $cat->term_id; } //IF on a category page get the id of the category } elseif( is_category() ){ $cat_ids[] = get_query_var('cat'); } //print_r( get_the_category() ); ///print_r( $cat_ids ); //Bring in the Styling if( $instance['css'] == 'checked' ){ echo ''; } //Go through each category there will be only one if this is a category page mulitple possible if this is single foreach( $cat_ids as $cat_id ){ $cat_ancestors = array (); $cat_ancestors[] = $cat_id ; do { $cat_id = get_category($cat_id ); $cat_id = $cat_id->parent; $cat_ancestors[] = $cat_id ; } while ($cat_id ); //Reverse the array to start at the last $cat_ancestors = array_reverse( $cat_ancestors ); //forget the [0] because the parent of top parent is always 0 $top_cat = $cat_ancestors[1]; //Keeps track or already used top levels so this won't double up if( in_array( $top_cat, $already_top ) ){ continue; } $already_top[] = $top_cat; //Check for children $all_categories = get_categories( array( 'child_of' => $top_cat ) ); //for depreciation $all = $all_categories; //If there are any child categories or the include childless parent is checked if( !empty($all_categories ) || ($instance['include_childless_parent'] == 'checked' && !in_array($top_cat, $exclude)) ){ //Creates a new widget for each category the single page has if the options are selected to do so if( !$asm_once || ($instance['new_widget'] == 'widget') ){ echo ''; } } //End if any children or include childless parent } //End of each cat loop //IF we were waiting for all the individual lists to complete if( !$close && $asm_once ){ //End the Widget Area echo ' '; } } #== /widget() } #== /Clas