我正准备开发一个主题,但我有一个小问题。我正在尝试使用以下代码向我的主题添加侧栏:
function theme_2_widgets_init() {
register_sidebar( array(
\'name\' => __(\'Sidebar\', \'theme_2\'),
\'id\' => \'sidebar-1\',
\'description\' => __(\'Add widgets here to appear in your sidebar.\', \'theme_2\' ),
\'before_widget\' => \'<aside id="%1$s" class="widget %2$s">\',
\'after_widget\' => \'</aside>\',
\'before_title\' => \'<h4 class="widget-title">\',
\'after_title\' => \'</h4>\',
) );
}
add_action(\'widgets_init\', \'theme_2_widgets_init\');
问题是,当我转到Appearence->widgets时,我的侧边栏就在那里,但有一个明确的侧边栏,上面写着“这个侧边栏不再可用,也不会显示在你的网站上的任何地方…”
这正常吗?
SO网友:Md. Mrinal Haque
改变\'id\' => \'sidebar-1\',
作为您自己的侧栏名称。例如,新侧栏名称为sidebar-2
然后,我们的职能将-
add_action( \'widgets_init\', \'theme_slug_widgets_init\' );
function twentyfifteen_widgets_init() {
register_sidebar( array(
\'name\' => __( \'Widget Area\', \'twentyfifteen\' ),
\'id\' => \'sidebar-2\',
\'description\' => __( \'Add widgets here to appear in your sidebar.\', \'twentyfifteen\' ),
\'before_widget\' => \'<aside id="%1$s" class="widget %2$s">\',
\'after_widget\' => \'</aside>\',
\'before_title\' => \'<h2 class="widget-title">\',
\'after_title\' => \'</h2>\',
) );
}
add_action( \'widgets_init\', \'twentyfifteen_widgets_init\' );
`