要注册边栏小部件,请转到Appearance > Editor
并选择function.php
从右边。然后将此代码复制并粘贴到function.php
文件
function custom_register_widgets() {
register_sidebar( array (
\'name\' => __( \'Sidebar widget\'),
\'id\' => \'sidebar-custom\',
\'description\' => __( \'Widgets dragged here will appear in the right sidebar.\' ),
\'before_widget\' => \'<aside id="%1$s" class="widget %2$s">\',
\'after_widget\' => \'</aside>\',
\'before_title\' => \'<h5 class="widget-title"><span>\',
\'after_title\' => \'</span></h5>\'
) );
}
add_action( \'widgets_init\', \'custom_register_widgets\' );
现在您需要调用小部件来显示它。再次从右侧选择
sidebar.php
并将此代码粘贴到所需的位置:
<?php
if(is_active_sidebar(\'sidebar-custom\')){
dynamic_sidebar(\'sidebar-custom\');
}?>