I have a two column page design in WordPress.
I would like to display a different widget based upon the allocated WordPress category in the right hand side column using a functions command.
My question is this: is my approach the 'correct method?' I have 3 sets of arrays in an "IF Statement"
I should add that it works!
But - I want to make sure that it is correctly done:
function my_custom_sidebar_display( $sidebar ) {
// Return a different sidebar for different categories
if ( in_category(array('Apples','Pears','Peaches')) ) {
return 'sidebar-fruit';
}
if ( in_category(array('potatoes','carrots','celery')) ) {
return 'sidebar-vegetables';
}
}
if ( in_category(array('monkeys','rhino','cheetah')) ) {
return 'sidebar-animals';
}
// Return theme defined sidebar area
else {
return $sidebar;
}
}
add_filter( 'ocean_get_sidebar', 'my_custom_sidebar_display' );
Aucun commentaire:
Enregistrer un commentaire