创建child theme (如果你还没有)和register two sidebars:
function wpse_151695_register_sidebars() {
register_sidebar(
array(
\'name\' => \'News\',
\'id\' => \'sidebar-news\',
)
);
register_sidebar(
array(
\'name\' => \'Blog\',
\'id\' => \'sidebar-blog\',
)
);
}
add_action( \'widgets_init\', \'wpse_151695_register_sidebars\' );
然后在你的
sidebar.php
:
if ( is_singular() ) {
// For single posts, show the sidebar relevant to the category it\'s assigned to.
if ( has_category( \'news\' ) )
dynamic_sidebar( \'news\' );
elseif ( has_category( \'blog\' ) )
dynamic_sidebar( \'blog\' );
} elseif ( is_category() ) {
if ( is_category( \'news\' ) )
dynamic_sidebar( \'news\' );
elseif ( is_category( \'blog\' ) )
dynamic_sidebar( \'blog\' );
}