有没有可能在WooCommerce钩子中添加一个侧边栏?

时间:2013-09-12 作者:Gman

我正在尝试在woocommerce-woocommerce\\u-before\\u-shop\\u-loop-hook中添加一个侧栏。我在函数中使用以下代码。php文件:

add_action( \'woocommerce_before_shop_loop\', \'my_custom_before_shop_loop_sidebar\', 1);
function my_custom_before_shop_loop_sidebar() {
      echo get_sidebar(\'my_custom_sidebar\');
}
我遇到的问题是,它显示wordpress默认侧栏,而不是带有my\\u custom\\u侧栏id的侧栏。

有没有办法做到这一点?谢谢

啊,顺便说一下,我正在注册侧边栏,如下所示:

/**
 * Register sidebars
*/
function meir_widgets_init() {
    register_sidebar( array(
        \'name\' => \'My Custom Sidebar\',
        \'id\' => \'my_custom_sidebar\',
        \'description\' => \'Sidebar for top filters.\',
        \'before_widget\' => \'<div id="%1$s" class="widget %2$s">\',
        \'after_widget\' => \'<div class="clear"></div></div></div></div>\',
        \'before_title\' => \'<h3 class="widget-title">\',
        \'after_title\' => \'</h3><div class="filter_box"><div class="filter_wrapper">\',
    ) );
}
add_action( \'widgets_init\', \'meir_widgets_init\' );

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

嗯,我真的弄明白了。保留代码以防以后有人需要:

// Add sidebar for shop loop header  
function my_custom_before_shop_loop_sidebar() {

dynamic_sidebar(\'shop-loop-header-sidebar\');

}

add_action( \'woocommerce_before_shop_loop\', \'my_custom_before_shop_loop_sidebar\', 2);

结束