Monday, January 5, 2015

Wordpress: Adding a dropdown for the categories and tags used on the site

This is just a simple example when you need to filter posts by categories and/or tags...

 <form method="post" action="<?php bloginfo('url');?>/results/">  
      <input type="hidden" name="filter_jobs" value="true" />  
      <label for="cat">Categories</label>  
           $choose_text = '--- '.__('Choose', '123').' ---'; //First option to show  
           wp_dropdown_categories(array(show_option_none => $choose_text));  
      <label for="tags">Tags</label>  
           $tag_list = wp_tag_cloud('smallest=10&largest=10&number=0&format=array');  
      <select name="tags" id="tags">  
           <option value=""><?php echo $choose_text;?></option>  
                foreach ($tag_list as $value) {  
                     echo '<option value="'.strip_tags($value).'">'.strip_tags($value).'</option>';  
      <input type="submit" value="Search" />       

No comments:

Post a Comment