以下是我的一个网站上的一个实例:
if(is_page(\'about-us\')) {
dynamic_sidebar(\'main-sidebar\');
}
if(is_page(\'contribute\')) {
dynamic_sidebar(\'page-sidebar\');
}
if(is_front_page() && is_page(\'about-us\')) {
dynamic_sidebar(\'main-sidebar\');
}
if(!is_front_page() && is_page(\'about-us\')) {
dynamic_sidebar(\'another-sidebar\');
}
if(is_category(\'archive\')) {
dynamic_sidebar(\'archive-sidebar\');
}
您可以看到我需要不同小部件的各种场景。
此外,在函数中。php,我有以下代码:
if(function_exists(\'register_sidebar\')) {
register_sidebar(array(\'name\' => \'Homepage Sidebar\'));
register_sidebar(array(\'name\' => \'Blog Sidebar\'));
register_sidebar(array(
\'name\' => __(\'Main Sidebar\'),
\'id\' => \'main-sidebar\',
\'description\' => \'This sidebar is active on Homepage, Despre Noi, Directioneaza 2%, and individual profiles.\'
));
register_sidebar(array(
\'name\' => __(\'Archive Sidebar\'),
\'id\' => \'archive-sidebar\',
\'description\' => \'This sidebar is active on Archive page.\'
));
}