duplicate sidebar

时间:2012-11-27 作者:Rommel Castro A

我对侧边栏有问题。我有4个侧边栏:“Essential”、“Essential+”、“Premier”和“Premier+”。

register_sidebar(
     array(
         \'name\'          => __(\'Essential Plan\'),
         \'before_widget\' => \'<ul>\',
         \'after_widget\'  => \'</ul>\',
         \'before_title\'  => \'\',
         \'after_title\'   => \'\'
    )
);
register_sidebar(
    array(
         \'name\'          => __(\'Premier Plan\'),
         \'before_widget\' => \'<ul>\',
         \'after_widget\'  => \'</ul>\',
         \'before_title\'  => \'\',
         \'after_title\'   => \'\'
    )
);
register_sidebar(
    array(
         \'name\'          => __(\'Essential+ Plan\'),
         \'before_widget\' => \'<ul>\',
         \'after_widget\'  => \'</ul>\',
         \'before_title\'  => \'\',
         \'after_title\'   => \'\'
    )
);
register_sidebar(
    array(
         \'name\'          => __(\'Premier+ Plan\'),
         \'before_widget\' => \'<ul>\',
         \'after_widget\'  => \'</ul>\',
         \'before_title\'  => \'\',
         \'after_title\'   => \'\'
    )
);
我必须在同一页中呈现“Premier”和“Premier+”。当我这样做时,WordPress会为两个页面呈现相同的内容,我该如何解决这个问题
为什么会发生这种情况?

1 个回复
最合适的回答,由SO网友:Chip Bennett 整理而成

尝试给出一个unique ID 到每个动态侧栏,通过id 参数传递给register_sidebar():

register_sidebar(
        array(
             \'id\'            => \'essential\',
             \'name\'          => __(\'Essential Plan\'),
             \'before_widget\' => \'\',
             \'after_widget\'  => \'\',
             \'before_title\'  => \'\',
             \'after_title\'   => \'\'
        )
    );

    register_sidebar(
        array(
             \'id\'            => \'premier\',
             \'name\'          => __(\'Premier Plan\'),
             \'before_widget\' => \'\',
             \'after_widget\'  => \'\',
             \'before_title\'  => \'\',
             \'after_title\'   => \'\'
        )
    );

    register_sidebar(
        array(
             \'id\'            => \'essential-plus\',
             \'name\'          => __(\'Essential+ Plan\'),
             \'before_widget\' => \'\',
             \'after_widget\'  => \'\',
             \'before_title\'  => \'\',
             \'after_title\'   => \'\'
        )
    );

    register_sidebar(
        array(
             \'id\'            => \'premier-plus\',
             \'name\'          => __(\'Premier+ Plan\'),
             \'before_widget\' => \'\',
             \'after_widget\'  => \'\',
             \'before_title\'  => \'\',
             \'after_title\'   => \'\'
        )
    );
然后按ID分别调用:

dynamic_sidebar( \'essential\' );
dynamic_sidebar( \'premier\' );
dynamic_sidebar( \'essential-plus\' );
dynamic_sidebar( \'premier-plus\' );
不过,您应该能够通过name ID:

dynamic_sidebar( \'Essential Plan\' );
dynamic_sidebar( \'Premier Plan\' );
dynamic_sidebar( \'Essential+ Plan\' );
dynamic_sidebar( \'Premier+ Plan\' );
。。。除非“+”从参数中清除?

结束

相关推荐

如何将Get_Sidebar存储在变量中?

Possible Duplicate:how do I get_sidebar into a varaible? 我发现how do I get_sidebar into a varaible? 但目标与我的不同,因此答案不适用。我想获得一个侧栏并将其保存到一个变量中,以便创建一个if/elseif语句,该语句将根据条件条件打印正确的侧栏。例如,我现在有这样的东西。。。if ( is_page(1) ) { $sidebar = get_sidebar(\'wine\'); }