Show different sidebar on taxonomy pages when a default is set

Why don’t you simply create a new sidebar… It will be clearer for you and will lighten your sidebar.php.

Create a file in your theme folder : sidebar-thenameyouwant.php
put your sidebar code there like this ex :

    <div id="secondary">
        <?php dynamic_sidebar( 'sidebar-xyz' ); ?>
    </div><!-- #secondary .widget-area -->

in your themes function.php… add :

    register_sidebar( array(
    'name' => 'Custom posts sb',
    'id' => 'sidebar-xyz',
    'description' => 'blablabla',
    'before_widget' => '<aside id="%1$s" class="widget %2$s">',
    'after_widget' => "</aside>",
    'before_title' => '<h3 class="widget-title">',
    'after_title' => '</h3>',
) );

then in your custom taxonomy page you call the right sidebar

<?php get_sidebar('thenameyouwant');    ?>

it will automatically load the code from your sidebar-thenameyouwant.php

Of course, the new sidebar will be in your admin Appearance > Widgets… You can slide widgets into it or just edit the new sidebar file directly. If you want to load widgets you have to have the dynamic_sidebar php call like above…

hope this helps.