
cat+tag filter
By: a guest on
May 25th, 2012 | syntax:
PHP | size: 1.86 KB | hits: 35 | expires: Never
function tag_options($type){
global $ctf_options, $current_tag;
if(is_category){
$category = get_the_category();
$cat_ID = $category[0]->cat_ID;
$args = array(
'cat' => $cat_ID
);
query_posts($args);
if(have_posts()): while (have_posts()) : the_post();
$all_tag_objects = get_the_tags();
if($all_tag_objects){
foreach($all_tag_objects as $tag) {
if($tag->count > 0) {$all_tag_ids[] = $tag -> term_id;}
}
}
endwhile;endif;
$tags = array_unique($all_tag_ids);
}else{
$tags = get_tags();
}
if ($type == 1){
$options .= '<ul>';
foreach ($tags as $tag) {
$post_tag = get_term($tag, 'post_tag');
$options .= '<li>';
$options .= '<input type="checkbox" name="';
$options .= "tag[]";
$options .= '" value="' . $post_tag->slug . '"';
if (is_array($current_tag)) {if (in_array($post_tag->slug, $current_tag)) $options .= ' checked ';}
$options .= '>';
$options .= $post_tag->name;
if ($ctf_options['tags_count'] == 1) $options .= ' (' . $post_tag->count . ')';
$options .= '</li>';
}
$options .= '</ul>';
}
else {
$options .= '<select name="' . "tag[]" . '" id="ctf-tag-select" ><option value="-1">';
if ($ctf_options['all_tags_text'] != '') $options .= $ctf_options['all_tags_text']; else $options .=__('Any tag', 'cat-tag-filter');
$options .= '</option>';
foreach ($tags as $tag) {
$post_tag = get_term($tag, 'post_tag');
$options .= '<option value="' . $post_tag->slug . '"';
if (is_array($current_tag)) {if (in_array($post_tag->slug, $current_tag)) $options .= ' selected="selected" ';}
$options .= '>';
$options .= $post_tag->name;
if ($ctf_options['tags_count'] == 1) $options .= ' (' . $post_tag->count . ')';
$options .= '</option>';
}
$options .= '</select>'; }
return $options;
}