context
we have created custom taxonomy displayed search filter parameter in third party plugin (in form of checkbox). however, want list of taxonomies displayed ordered slug.
this function generates checkbox , outputs taxonomy - part customized starts @ " //create attributes" .
public function checkbox($args) { //init defaults & vars $input_args = $this->prepare_input_args($args, "checkbox"); $input_name = $input_args['attributes']['name']; unset($input_args['attributes']['name']); //filter input arguments before html generated - allowing options modified if(has_filter('sf_input_object_pre')) { $input_args = apply_filters('sf_input_object_pre', $input_args, $this->sfid); } //prepare html $attibutes_html = $this->convert_attributes_to_html($input_args['attributes']); $open_child_count = 0; ob_start(); ?> <ul<?php echo $attibutes_html; ?>> <?php $last_option_depth = 0; $option_count = count($input_args['options']); $current_depth = 0; $is_li_open = array(); //echo "<ul>"; for($i=0; $i<$option_count; $i++) { $option = &$input_args['options'][$i]; if(!isset($option->attributes)) { $option->attributes = array( 'class' => '', 'id' => '' ); } //check default has been set , set $option->attributes['type'] = "checkbox"; $option->attributes['value'] = $option->value; $option->attributes['name'] = $input_name; $option->attributes['html'] = ''; $container_attributes = array(); if($this->is_option_selected($option, $input_args['defaults'])) { $option->attributes['checked'] = 'checked'; $option->attributes['class'] = trim($option->attributes['class']).' sf-option-active'; } else { if(isset($option->attributes['checked'])) { unset($option->attributes['checked']); } } //now want put class attribute on li, , remove input $option_class = $option->attributes['class']; $option->attributes['class'] = $input_args['input_class']; $input_id = $this->generate_input_id($input_name."_".$option->value); $option->attributes['id'] = $input_id; $container_attibutes_html = ""; if(isset($option->count)) { $container_attributes['data-sf-count'] = $option->count; $container_attibutes_html = $this->convert_attributes_to_html($container_attributes); } //create attributes $input_attibutes_html = $this->convert_attributes_to_html($option->attributes); $option_label = $option->label; $option_html = $option->attributes['value']; if($input_name == "_sft_module_authors[]"){ $tax_name = "module_authors"; } else if ($input_name == "_sft_module_mindset[]") { $tax_name = "module_mindset"; } else if ($input_name == "_sft_module_language[]") { $tax_name = "module_language"; } else if ($input_name == "_sft_management_levels[]") { $tax_name = "management_levels"; } else{ $tax_name = "wpdmcategory"; } // id of given category $my_term = get_term_by('slug',$option->value,$tax_name); $category_id = $my_term->term_id; $category_desc = $my_term->description; $category_name = $my_term->name; $meta_image = get_wp_term_image($category_id); // url of category $category_link = get_category_link( $category_id ); if ($input_name == "_sft_module_authors[]") { echo '<li class="accordion-content '.$option_class.'"'.$container_attibutes_html.'><input '.$input_attibutes_html.'><label class="sf-label-checkbox" for="'.$input_id.'">' . $category_name . '</label><a class="emodal-post-'.$category_id.'" href="'.$category_link.'"><i class="fa fa-info-circle"></i></a>'; echo do_shortcode("[modal id='post-". $category_id ."' size='small' title='". $category_name ."']". "<div class='col-md-8'>" . $category_desc . "</div>" . "<div class='col-md-4'>" . "<div class='img-wrap'><img src='".$meta_image."'></div></div>" . "[/modal]"); } else if ($input_name == "_sft_module_mindset[]") { echo '<li class="accordion-content '.$option_class.'"'.$container_attibutes_html.'><input '.$input_attibutes_html.'><label class="sf-label-checkbox" for="'.$input_id.'">' . $category_name . '</label><a class="emodal-post-'.$category_id.'" href="'.$category_link.'"><i class="fa fa-info-circle"></i></a>'; echo do_shortcode("[modal id='post-". $category_id ."' size='small' title='". $category_name ."']". "<div class='col-md-12'>" . $category_desc . "</div>" . "[/modal]"); } else if ($input_name == "_sft_module_language[]") { echo '<li class="accordion-content '.$option_class.'"'.$container_attibutes_html.'><input '.$input_attibutes_html.'><label class="sf-label-checkbox" for="'.$input_id.'">' . $category_name; } else if ($input_name == "_sft_management_level[]") { echo '<li class="accordion-content '.$option_class.'"'.$container_attibutes_html.'><input '.$input_attibutes_html.'><label class="sf-label-checkbox" for="'.$input_id.'">' . $category_name; } else { echo '<li class="accordion-content '.$option_class.'"'.$container_attibutes_html.'><input '.$input_attibutes_html.'><label class="sf-label-checkbox" for="'.$input_id.'">' . $category_name . '</label><a class="emodal-post-'.$category_id.'" href="'.$category_link.'"><i class="fa fa-info-circle"></i></a>'; echo do_shortcode("[modal id='post-". $category_id ."' size='small' title='". $category_name ."']". "<div class='col-md-12'>" . $category_desc . "</div>" . "[/modal]"); } if(isset($option->depth)) {//then depth calculations $current_depth = $option->depth; $close_li = true; $open_child_list = false; $close_ul = false; $next_depth = -1; if(isset($input_args['options'][$i+1])) { $next_option = $input_args['options'][$i+1]; $next_depth = $next_option->depth; } if($next_depth!=-1) { if($next_depth!=$current_depth) {//there change in depth if($next_depth>$current_depth) {//then need open child list //and, not close current li $open_child_list = true; $close_li = false; } else { $close_ul = true; } } } if($open_child_list) { $open_child_count++; echo '<ul class="children">'; } if($close_li) { echo "</li>"; } if($close_ul) { $diff = $current_depth - $next_depth; $open_child_count = $open_child_count - $diff; $str_repeat = str_repeat("</ul></li>", $diff); echo $str_repeat; } } } $str_repeat = str_repeat("</ul></li>", (int)$open_child_count); echo $str_repeat; ?> </ul> <?php $output = ob_get_clean(); return $output; }
Comments
Post a Comment