大家好,我想向我的wordpress站点添加多个侧栏。我目前在函数中注册了两个侧栏。php类似:
function themename_widgets_init() {
register_sidebar( array(
\'name\' => __( \'Sidebar\', \'themename\' ),
\'id\' => \'sidebar-1\',
\'description\' => \'Sidebar for all pages\',
\'before_widget\' => \'<aside id="%1$s" class="widget %2$s">\',
\'after_widget\' => \'</aside>\',
\'before_title\' => \'<h1 class="widget-title">\',
\'after_title\' => \'</h1>\',
) );
register_sidebar( array(
\'name\' => __( \'Sidebartwo\', \'themename\' ),
\'id\' => \'sidebar-2\',
\'description\' => \'Sidebar for product page\',
\'before_widget\' => \'<aside id="%1$s" class="widget %2$s">\',
\'after_widget\' => \'</aside>\',
\'before_title\' => \'<h1 class="widget-title">\',
\'after_title\' => \'</h1>\',
) );
}
add_action( \'widgets_init\', \'themename_widgets_init\' );
在我的侧边栏中。php我目前有这段代码,如果我没有添加任何小部件,它会将默认数据添加到我的侧栏中。
<div id="secondary" class="widget-area" role="complementary">
<?php if ( ! dynamic_sidebar( \'sidebar-1\' ) ) : ?>
<aside id="search" class="widget widget_search">
<?php get_search_form(); ?>
</aside>
<aside id="archives" class="widget">
<h1 class="widget-title"><?php _e( \'Archives\', \'themename\' ); ?></h1>
<ul>
<?php wp_get_archives( array( \'type\' => \'monthly\' ) ); ?>
</ul>
</aside>
<aside id="meta" class="widget">
<h1 class="widget-title"><?php _e( \'Meta\', \'themename\' ); ?></h1>
<ul>
<?php wp_register(); ?>
<li><?php wp_loginout(); ?></li>
<?php wp_meta(); ?>
</ul>
</aside>
<?php endif; // end sidebar widget area ?>
</div><!-- #secondary -->
有没有人知道如何对我的侧边栏-2进行同样的操作?根据我所读的内容,我必须创建一个侧边栏-2。我所做的php,包括与上面相同的代码,如下所示:
<aside id="search" class="widget widget_search">
<?php get_search_form(); ?>
</aside>
<aside id="archives" class="widget">
<h1 class="widget-title"><?php _e( \'Archives\', \'themename\' ); ?></h1>
<ul>
<?php wp_get_archives( array( \'type\' => \'monthly\' ) ); ?>
</ul>
</aside>
<aside id="meta" class="widget">
<h1 class="widget-title"><?php _e( \'Meta\', \'themename\' ); ?></h1>
<ul>
<?php wp_register(); ?>
<li><?php wp_loginout(); ?></li>
<?php wp_meta(); ?>
</ul>
</aside>
<?php endif; // end sidebar widget area ?>
</div><!-- #secondary -->
但不幸的是,它不起作用。有人知道为什么吗?