您需要在主题函数中注册小部件区域。php文件。您的代码应该是这样的。
//register the widget area
function your_function_name() {
register_sidebar(array(
\'name\' => esc_html__(\'Sidebar\', \'your_theme_name\'),
\'id\' => \'sidebar-1\',
\'description\' => esc_html__(\'Add widgets here.\', \'your_theme_name\'),
\'before_widget\' => \'<section id="%1$s" class="widget %2$s">\',
\'after_widget\' => \'</section>\',
\'before_title\' => \'<h2 class="widget-title">\',
\'after_title\' => \'</h2>\',
)); }
add_action(\'widgets_init\', \'your_function_name\'); //This hooks into WordPress wigets_init function.
您可以了解有关widgetizing主题的更多信息
here. 学习和理解挂钩、动作和过滤器的另一个好地方是
site, 这真的帮助了我。我希望这些都能有所帮助。=)