php - Wordpress change sidebar for specific post category -


i want change sidebar of category "magazin". have tried code:

<?php  $thecat = single_cat_title( '', false ); ?>         <?php  if ($thecat == 'magazin') { dynamic_sidebar('magazin'); } else { dynamic_sidebar ('sidebar'); }  ?> 

but sidebar "magazin" not show in magazin category posts. if set that:

dynamic_sidebar('magazin'); 

it shows sidebar (but in every category).

to show custom sidebar different categories in single post can use following code:

$cat = get_the_category();  if ( ! empty( $cat ) ) {     $cat_name = $cat[0]->name;     switch ($cat_name) {         case 'category i':             include ('sidebar-cat-i.php');             break;         case 'category ii':             include ('sidebar-cat-ii.php');             break;         case 'category iii':             include ('sidebar-cat-iii.php');             break;     } } else {   get_sidebar(); } 

Comments