个性化阅读
专注于IT技术分析

在WordPress中添加多个小部件区域

我正在尝试添加多个窗口小部件区域, 以下代码已添加多个窗口小部件。它起作用, 但是第二个侧边栏的名称重复两次。有什么解决办法吗?

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>' 
 ));
}

#1


register_sidebars注册多个工具条, 并且你为第二个函数提供了2作为参数, 这就是为什么它要注册两个工具条的原因。

在你的情况下, 最好使用register_sidebar。

参考:

http://codex.wordpress.org/Function_Reference/register_sidebar

http://codex.wordpress.org/Function_Reference/register_sidebars


#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' => '' )); }

#3


在以下代码中, 我正在添加代码以在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>', ) );
    }

我认为这将有助于我解决其他任何问题

赞(0)
未经允许不得转载:srcmini » 在WordPress中添加多个小部件区域

评论 抢沙发

评论前必须登录!