Ask your WordPress questions! Pay money and get answers fast! Comodo Trusted Site Seal
Official PayPal Seal

widget logic plugin question WordPress

  • SOLVED

I use this is_single() to have a widget show up on my single page template. I have a category with the id of "1", and I do not want the widget to show up on the single template page. Any solution?

Answers (2)

2010-05-14

Utkarsh Kukreti answers:

is_single() && !is_category(1)

Try this
is_single() && !in_category(1)


Rick Bible comments:

this does not work, right idea and direction,

2010-05-14

Oleg Butuzov answers:

on template

if (is_single() && !in_array(1, get_post_categories_ids()) && (!function_exists('dynamic_sidebar') || !dynamic_sidebar()) ){
// here will be your widgets.
}


in functions php



function get_post_categories_ids(){
global $post;
$categorylist = get_the_category($post->ID);
if (count($categorylist) == 0) return array();
$cat = array();
foreach($categorylist as $categ){
$cat[] = $categ->term_id;
}
return $cat;
}

if ( function_exists('register_sidebar') ) {
register_sidebar(array(
'before_widget' => '<li id="%1$s" class="widget %2$s">',
'after_widget' => '</li>',
'before_title' => '<h2 class="widgettitle">',
'after_title' => '</h2>',
));
}