Advertisement
Guest User

cat+tag filter

a guest
May 25th, 2012
174
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 1.86 KB | None | 0 0
  1. function tag_options($type){
  2.   global $ctf_options, $current_tag;
  3. if(is_category){
  4. $category = get_the_category();
  5.             $cat_ID = $category[0]->cat_ID;
  6.  
  7.   $args = array(
  8.     'cat'      => $cat_ID
  9. );
  10. query_posts($args);
  11.     if(have_posts()): while (have_posts()) : the_post();
  12.         $all_tag_objects = get_the_tags();
  13.         if($all_tag_objects){
  14.             foreach($all_tag_objects as $tag) {
  15.                 if($tag->count > 0) {$all_tag_ids[] = $tag -> term_id;}
  16.             }
  17.         }
  18.     endwhile;endif;
  19.     $tags = array_unique($all_tag_ids);
  20. }else{
  21.   $tags = get_tags();
  22. }
  23.   if ($type == 1){
  24.    $options .= '<ul>';
  25.   foreach ($tags as $tag) {
  26.     $post_tag = get_term($tag, 'post_tag');
  27.    $options .= '<li>';
  28.     $options .= '<input type="checkbox" name="';
  29.     $options .= "tag[]";
  30.     $options .= '" value="' . $post_tag->slug . '"';
  31.     if (is_array($current_tag)) {if (in_array($post_tag->slug, $current_tag)) $options .= ' checked ';}
  32.     $options .= '>';
  33.     $options .= $post_tag->name;
  34.     if ($ctf_options['tags_count'] == 1) $options .= ' (' . $post_tag->count . ')';
  35.     $options .= '</li>';
  36.   }
  37.   $options .= '</ul>';
  38.   }
  39.   else {  
  40.  
  41.  $options .= '<select name="' . "tag[]" . '" id="ctf-tag-select" ><option value="-1">';
  42.   if ($ctf_options['all_tags_text'] != '') $options .= $ctf_options['all_tags_text']; else $options .=__('Any tag', 'cat-tag-filter');
  43.   $options .= '</option>';
  44.   foreach ($tags as $tag) {
  45.   $post_tag = get_term($tag, 'post_tag');
  46.     $options .= '<option value="' . $post_tag->slug . '"';
  47.     if (is_array($current_tag)) {if (in_array($post_tag->slug, $current_tag)) $options .= ' selected="selected" ';}
  48.     $options .= '>';
  49.     $options .= $post_tag->name;
  50.     if ($ctf_options['tags_count'] == 1) $options .= ' (' . $post_tag->count . ')';
  51.     $options .= '</option>';
  52.   }
  53.   $options .= '</select>'; }
  54.   return $options;
  55. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement