<?php
global $_opt, $wp_query;
$custom_sidebar = get_post_meta($wp_query->queried_object->ID, PFIX.'_custom_sidebar',true); 


if (is_active_sidebar( $custom_sidebar ) && !empty($_opt[PFIX."_custom_sidebars"][$custom_sidebar])):
?>

		<div id="primary" class="widget-area custom-widget-<?php echo $custom_sidebar;?>">
				<?php dynamic_sidebar( $custom_sidebar ); ?>
		</div><!-- #custom(<?php echo $custom_sidebar;?>) .widget-area -->


<?php else:  


if (is_search()) {$get_sidebar = 'searchpage-widget-area';}
elseif (is_archive()) {$get_sidebar = 'archive-widget-area';}
elseif (is_page()) {$get_sidebar = 'primary-widget-area';}
else {$get_sidebar = 'blog-widget-area';}


?>

		<div id="primary" class="widget-area">

			<?php if ( ! dynamic_sidebar( $get_sidebar ) ) : ?>
            
				<?php get_sidebar_defaults( $get_sidebar );?>
            
            <?php endif;?>
		
        <div class="cf"></div>
        </div><!-- /#primary .widget-area -->

<?php endif; ?>