0
votes

I want to change the sidebar of the category "Magazin". I have tried this code:

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

But the sidebar "Magazin" does not show in the magazin category posts. However if i just set it just like that:

dynamic_sidebar('Magazin');

It shows the sidebar properly (but in every category).

1
did you get this working?Cerveser

1 Answers

0
votes

To show a custom sidebar for different categories in a single post you can use the 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();
}