the following code add dynamically WordPress Categories as horizontal tabs for a Magazine Plugin.
I need to make theme appear as a drop down list.
The Responsible Function is :
function sort_buttons()
{
$sort_terms = get_terms( $this->atts['taxonomy'] , array('hide_empty'=>true) );
$current_page_terms = array();
$term_count = array();
$display_terms = is_array($this->atts['categories']) ? $this->atts['categories'] : array_filter(explode(',',$this->atts['categories']));
$output = "<div class='av-magazine-sort ' data-magazine-id='".self::$magazine."' >";
$first_item_name = apply_filters('avf_magazine_sort_first_label', __('All','avia_framework' ), $this->atts);
$output .= "<div class='av-sort-by-term'>";
$output .= '<a href="#" data-filter="sort_all" class="all_sort_button active_sort"><span class="inner_sort_button"><span>'.$first_item_name.'</span></span></a>';
foreach($sort_terms as $term)
{
if (!in_array($term->term_id, $display_terms)) continue;
if(!isset($term_count[$term->term_id])) $term_count[$term->term_id] = 0;
$term->slug = str_replace('%', '', $term->slug);
$output .= "<span class='text-sep {$term->slug}_sort_sep'>/</span>";
$output .= '<a href="#" data-filter="sort_'.$term->term_id.'" class="'.$term->slug.'_sort_button " ><span class="inner_sort_button">';
$output .= "<span>".esc_html(trim($term->name))."</span>";
$output .= "</span>";
$output .= "</a>";
$this->atts['extra_categories'][] = $term->term_id;
}
$output .= "</div></div>";
if(count($this->atts['extra_categories']) <= 1) return "";
return $output;
}
I try to add the following code where the drop down list appear successfully but is links not working.
function sort_buttons()
{
$sort_terms = get_terms( $this->atts['taxonomy'] , array('hide_empty'=>true) );
$current_page_terms = array();
$term_count = array();
$display_terms = is_array($this->atts['categories']) ? $this->atts['categories'] : array_filter(explode(',',$this->atts['categories']));
$output = "<div class='av-magazine-sort ' data-magazine-id='".self::$magazine."' >";
$first_item_name = apply_filters('avf_magazine_sort_first_label', __('All','avia_framework' ), $this->atts);
$output .= "<div class='av-sort-by-term'><select>";
$output .= '<option><a href="#" data-filter="sort_all" class="all_sort_button active_sort"><span class="inner_sort_button"><span>'.$first_item_name.'</span></span></a></option>';
foreach($sort_terms as $term)
{
if (!in_array($term->term_id, $display_terms)) continue;
if(!isset($term_count[$term->term_id])) $term_count[$term->term_id] = 0;
$term->slug = str_replace('%', '', $term->slug);
$output .= "<span class='text-sep {$term->slug}_sort_sep'>/</span>";
$output .= '<option><a href="#" data-filter="sort_'.$term->term_id.'" class="'.$term->slug.'_sort_button " ><span class="inner_sort_button">';
$output .= "<span>".esc_html(trim($term->name))."</span>";
$output .= "</span>";
$output .= "</option></a>";
$this->atts['extra_categories'][] = $term->term_id;
}
$output .= "</select></div></div>";
if(count($this->atts['extra_categories']) <= 1) return "";
return $output;
}
Links inside
<option>
tag are not allowed and will not function. Below is an example of non-working<select>
and quick-and-dirty solution for<select>
if you have a list of links.However your links have
#
as URL withdata-
attributes meaning that the solution above won’t work. You need to use a dropdown menu (look for pure CSS or CSS/JS dropdown menu code). Below is just one example as seen at http://codepen.io/andornagy/pen/xhiJH :