Javascript 用bootstrap 3折叠注册工具条()WordPress

Javascript 用bootstrap 3折叠注册工具条()WordPress,javascript,php,wordpress,twitter-bootstrap,wordpress-theming,Javascript,Php,Wordpress,Twitter Bootstrap,Wordpress Theming,嗨,我正在建立一个自定义Wordpress主题和woocommerce主题。我需要侧边栏使用引导折叠。如果我可以让%1$s在这里更改或添加我自己的变量,并使用日期函数为它们提供唯一的id,那么它将起作用 函数onlineRugstoreCommust_widgets_init(){ 寄存器侧栏(数组)( 'name'=>esc_html_uuuu('Sidebar','onlinerugstorecustom'), 'id'=>'sidebar-1', 'description'=>esc_h

嗨,我正在建立一个自定义Wordpress主题和woocommerce主题。我需要侧边栏使用引导折叠。如果我可以让%1$s在这里更改或添加我自己的变量,并使用日期函数为它们提供唯一的id,那么它将起作用

函数onlineRugstoreCommust_widgets_init(){
寄存器侧栏(数组)(
'name'=>esc_html_uuuu('Sidebar','onlinerugstorecustom'),
'id'=>'sidebar-1',
'description'=>esc_html_uuu('addwidgets here','onlinerugstorecustom'),
'在小部件'=>''之前,
'在小部件'=>''之后,
'在标题之前'=>'+
',
) );
}
添加_操作('widgets_init','onlinerugstorecustom_widgets_init')使用(始终唯一)变量
%1$s
。像这样:

register_sidebar( array(
    'name'          => esc_html__( 'Sidebar', 'onlinerugstorecustom' ),
    'id'            => 'sidebar-1',
    'description'   => esc_html__( 'Add widgets here.', 'onlinerugstorecustom' ),
    'before_widget' => '<div class="widget panel panel-default %2$s">',
    'after_widget'  => '</div></div></div>',
    'before_title'  => '<div class="panel-heading" role="tab"><span class="plus-minus">+</span><h4 class="panel-title"><a class="collapsed" role="button" data-toggle="collapse" data-parent="#accordion" data-target="#%1$s" href="#%1$s" aria-expanded="false" aria-controls="collapseOne">',
    'after_title'   => '</a></h4></div>   <div id="%1$s" class="panel-collapse collapse" role="tabpanel" aria-labelledby="headingOne">
                              <div class="panel-body">',
) );
register\u侧栏(数组(
'name'=>esc_html_uuuu('Sidebar','onlinerugstorecustom'),
'id'=>'sidebar-1',
'description'=>esc_html_uuu('addwidgets here','onlinerugstorecustom'),
'在小部件'=>''之前,
'在小部件'=>''之后,
'在标题之前'=>'+
',
) );
我已经删除了before_小部件的唯一变量,并将其添加到要折叠的面板主体中。因为id始终必须是唯一的才能成为有效的HTML。

使用(始终唯一)变量
%1$s
。像这样:

register_sidebar( array(
    'name'          => esc_html__( 'Sidebar', 'onlinerugstorecustom' ),
    'id'            => 'sidebar-1',
    'description'   => esc_html__( 'Add widgets here.', 'onlinerugstorecustom' ),
    'before_widget' => '<div class="widget panel panel-default %2$s">',
    'after_widget'  => '</div></div></div>',
    'before_title'  => '<div class="panel-heading" role="tab"><span class="plus-minus">+</span><h4 class="panel-title"><a class="collapsed" role="button" data-toggle="collapse" data-parent="#accordion" data-target="#%1$s" href="#%1$s" aria-expanded="false" aria-controls="collapseOne">',
    'after_title'   => '</a></h4></div>   <div id="%1$s" class="panel-collapse collapse" role="tabpanel" aria-labelledby="headingOne">
                              <div class="panel-body">',
) );
register\u侧栏(数组(
'name'=>esc_html_uuuu('Sidebar','onlinerugstorecustom'),
'id'=>'sidebar-1',
'description'=>esc_html_uuu('addwidgets here','onlinerugstorecustom'),
'在小部件'=>''之前,
'在小部件'=>''之后,
'在标题之前'=>'+
',
) );

我已经删除了before_小部件的唯一变量,并将其添加到要折叠的面板主体中。因为id始终必须是唯一的才能成为有效的HTML。

我在这里找到了一个类似的线程,但答案似乎对我不起作用。你找到了使用wordpress的方法吗?您的jQuery是一个很好的解决方案。我在这里找到了一个类似的线程,但答案似乎对我不起作用。您找到了使用wordpress的方法吗?您的jQuery是一个很好的解决方案。感谢您的支持,我打算使用javascript作为备份,或者我想将面板作为html小部件放入,这意味着它们不是动态的。感谢Luuk Skeur,我将尝试您的代码。使用javascript不是一件坏事,在您的情况下,您可以将链接绑定到
parent().parent().next()
,甚至可以将
面板标题绑定到
面板主体
。由于某种原因,%1$s无法工作,这可能是因为Woocommerce扩展了wc_小部件类。我最终使用了jQuery,因为我不知道如何在php中解决它,但我希望我可以在数组中添加变量。为此,我打算使用javascript作为备份,或者我想将面板作为html小部件放入,这意味着它们不是动态的。感谢Luuk Skeur,我将尝试您的代码。使用javascript不是一件坏事,在您的情况下,您可以将链接绑定到
parent().parent().next()
,甚至可以将
面板标题绑定到
面板主体
。由于某种原因,%1$s无法工作,这可能是因为Woocommerce扩展了wc_小部件类。我最终使用jQuery来解决这个问题,因为我不知道如何在php中解决它,但我希望我可以在数组中添加变量。