下面是我编写代码的方法。已测试
Add to functions file
add_action( \'widgets_init\', \'wpsites_add_widget\' );
function wpsites_add_widget() {
register_sidebar(array(
\'name\'=>\'Sidebar-Aries\',
\'id\' => \'sidebar-aries\',
\'description\' =>\'Display all the contents of sidebar at Aries page.\',
\'before_widget\' => \'\',
\'after_widget\' => \'\',
\'before_title\' => \'\',
\'after_title\' => \'\',
));
}
或者您可以在模板中使用此代码并更改类以匹配现有小部件
Option 1 - Add to template
<?php if ( is_active_sidebar( \'sidebar-aries\' ) ) : ?>
<ul id="sidebar">
<?php dynamic_sidebar( \'sidebar-aries\' ); ?>
</ul>
<?php endif; ?>
Option 2 - Add to template
您还可以添加一个条件标记来控制小部件输出的页面
<?php if ( is_active_sidebar( \'sidebar-aries\' ) && is_conditional() ) : ?>
<ul id="sidebar">
<?php dynamic_sidebar( \'sidebar-aries\' ); ?>
</ul>
<?php endif; ?>
更换
is_conditional()
与您的
conditional tag