Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- --------------------------------------
- paste this code into functions.php
- --------------------------------------
- function get_terms_dropdown($taxonomies, $args){
- $myterms = get_terms($taxonomies, $args);
- $output ="<select class='cat_select' onChange='window.location.href=this.value'>";
- foreach($myterms as $term){
- $root_url = get_bloginfo('url');
- $term_taxonomy=$term->taxonomy;
- $term_slug=$term->slug;
- $term_name =$term->name;
- $link = $root_url.'/'.$term_taxonomy.'/'.$term_slug;
- $output .="<option value='".$link."'>".$term_name."</option>";
- }
- $output .="</select>";
- return $output;
- }
- --------------------------------------------------------------------------
- Paste where you want display category list as select option with link
- --------------------------------------------------------------------------
- <?php $taxonomies = array('category');
- $args = array('orderby'=>'title','hide_empty'=>true);
- echo get_terms_dropdown($taxonomies, $args); ?>
- ------- or -------------
- $taxonomies = array('category');
- $args = array('orderby'=>'count','hide_empty'=>true);
- echo get_terms_dropdown($taxonomies, $args);
- happy coding :)
Advertisement
Add Comment
Please, Sign In to add comment