编辑:
在这里,我在函数中注册了2个侧栏。名称为sidebar1和sidebar2的php。
$sidebar_args = array(
\'name\' => __( \'sidebar1\', \'theme_text_domain\' ),
\'id\' => \'sidebar-1\',
\'description\' => \'\',
\'class\' => \'\',
\'before_widget\' => \'<li id="%1$s" class="widget %2$s">\',
\'after_widget\' => \'</li>\',
\'before_title\' => \'<h2 class="widgettitle">\',
\'after_title\' => \'</h2>\' );
register_sidebar( $sidebar_args );
$sidebar_args_2 = array(
\'name\' => __( \'sidebar2\', \'theme_text_domain\' ),
\'id\' => \'sidebar-2\',
\'description\' => \'\',
\'class\' => \'\',
\'before_widget\' => \'<li id="%1$s" class="widget %2$s">\',
\'after_widget\' => \'</li>\',
\'before_title\' => \'<h2 class="widgettitle">\',
\'after_title\' => \'</h2>\' );
register_sidebar( $sidebar_args_2 );
现在在theme的页面上检索他们的名字,如下所示。
<?php
global $wp_registered_sidebars;
$my_sidebars = $wp_registered_sidebars;
foreach($my_sidebars as $my_sidebar){
echo $my_sidebar[\'name\'];
}
?>