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

Show different widget area in category.php based on category WordPress

  • SOLVED

Hello I would like to show a different widget area at the top of my category.php based on what category it is. Can this be done?

So when I look at category 'workouts' I would like to show:
<?php if ( !function_exists('dynamic_sidebar') || !dynamic_sidebar('Workouts Slider Widget') ) : ?><?php endif; ?>

And when I look at category 'food' I would like to show:
<?php if ( !function_exists('dynamic_sidebar') || !dynamic_sidebar('Food Slider Widget') ) : ?><?php endif; ?>

And when I look at category 'wellbeing' I would like to show:
<?php if ( !function_exists('dynamic_sidebar') || !dynamic_sidebar('Wellbeing Slider Widget') ) : ?><?php endif; ?>


Is this possible?

Thank you

Answers (3)

2014-01-04

Hariprasad Vijayan answers:

Hello,

Try this,

<?php
if(is_category( 'workouts' ))
{
if ( !function_exists('dynamic_sidebar') || !dynamic_sidebar('Workouts Slider Widget') ) : endif;
}
else if(is_category( 'food' ))
{
if ( !function_exists('dynamic_sidebar') || !dynamic_sidebar('Food Slider Widget') ) : endif;
}
else if(is_category( 'wellbeing' ))
{
if ( !function_exists('dynamic_sidebar') || !dynamic_sidebar('Wellbeing Slider Widget') ) : endif;
}
?>


Ross Gosling comments:

Thank you :)

2014-01-04

Abdelhadi Touil answers:

Hi.
What about using this plugin:

[[LINK href="http://wordpress.org/plugins/conditional-widgets/"]]http://wordpress.org/plugins/conditional-widgets/[[/LINK]]

?

2014-01-04

Sébastien | French WordpressDesigner answers:

this code is valid with many sidebars as you want if (is_category()) {

if ((!function_exists('dynamic_sidebar')) || (!dynamic_sidebar())) {
echo "static sidebar item";
} else {
$cat = get_query_var('cat');
$cat_name_widget = ucfirst($cat) . " Slider Widget";
if (is_active_sidebar($cat_name_widget)) dynamic_sidebar($cat_name_widget);
}
}