我正在尝试添加multiple widgets area
,我发布的以下代码是添加多个小部件。它有效,但second sidebar
的名称重复了两次。对它有任何解决方案吗?
if ( function_exists ('register_sidebar')){
register_sidebars (1, array(
'name' => 'wpwidget',
'id' => 'wpwidget',
'description' => 'Sidebar for showing ad and section list on the template career.php',
'before_widget' => '<div id="%1$s" class="widget %2$s">',
'after_widget' => '</div>',
'before_title' => '<h2 class="widgettitle">',
'after_title' => '</h2>'
));
register_sidebars (2, array(
'name' => 'wpwidget2',
'id' => 'wpwidget2',
'description' => 'Sidebar for showing ad and section list on the template example.php',
'before_widget' => '<div id="%1$s" class="widget %2$s">',
'after_widget' => '</div>',
'before_title' => '<h2 class="widgettitle">',
'after_title' => '</h2>'
));
}
答案 0 :(得分:2)
这段代码看起来像你注册了三个侧边栏1. wpwidget 2. wpwidget2 3.同样的wpwidget2
如果您尝试添加2个侧边栏,请编写此代码
if ( function_exists ('register_sidebars')){register_sidebars (2, array( 'name' => 'wpwidget %d', 'id' => 'wpwidget2', 'description' => 'Sidebar for showing ad and section list on the template example.php', 'before_widget' => '', 'after_widget' => '', 'before_title' => '', 'after_title' => '' )); }
答案 1 :(得分:1)
register_sidebars
注册多个侧栏,并且您已提供2
作为第二个功能的参数,这就是注册两个侧边栏的原因。
在您的情况下,最好使用register_sidebar
。
参考:
http://codex.wordpress.org/Function_Reference/register_sidebar
http://codex.wordpress.org/Function_Reference/register_sidebars
答案 2 :(得分:0)
在下面的代码中,我将添加代码以在wordpress中创建自定义多个窗口小部件或侧边栏。
add_action( 'widgets_init', 'my_custom_widget' );
function my_custom_widget{
register_sidebar( array(
'name' => __( 'Header Widget Area', 'themname' ),
'id' => 'sidebar-1',
'description' => __( 'Appears in the Header section of the site.', 'twentyfourteen' ),
'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' => __( 'Header Widget Area', 'themname' ),
'id' => 'sidebar-2',
'description' => __( 'Appears in the Header section of the site.', 'twentyfourteen' ),
'before_widget' => '<aside id="%1$s" class="widget %2$s">',
'after_widget' => '</aside>',
'before_title' => '<h1 class="widget-title">',
'after_title' => '</h1>',
) );
}
我认为这可以帮助我解决任何其他问题