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
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 :)
Abdelhadi Touil answers:
Hi.
What about using this plugin:
[[LINK href="http://wordpress.org/plugins/conditional-widgets/"]]http://wordpress.org/plugins/conditional-widgets/[[/LINK]]
?
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);
}
}