【问题标题】:How to add a sidebar to Woocommerce Shop Page?如何向 Woocommerce 商店页面添加侧边栏?
【发布时间】:2019-07-11 22:58:34
【问题描述】:

所以,我正在使用 Woocommerce 插件从头开始为 Wordpress 制作自己的主题。我似乎可以找到如何将侧边栏小部件添加到我的商店页面...在小部件菜单中没有它的区域,我似乎无法找到如何创建和编辑它...

谁能帮助我了解如何创建它以及我需要在我的子主题中创建哪些文件/代码?

【问题讨论】:

    标签: php wordpress woocommerce sidebar woocommerce-theming


    【解决方案1】:

    你需要使用这个函数在你的functions.php中创建一个小部件区域:

    if ( function_exists('register_sidebar') ) 
    register_sidebar(array(
        'name' => 'Sidebar',
        'before_widget' => '<div class = "widget">',
        'after_widget' => '</div>',
        'before_title' => '<h3>',
        'after_title' => '</h3>',
        )
    );
    

    并在您的主题中显示:

    <?php if ( !function_exists('dynamic_sidebar') || !dynamic_sidebar("Sidebar") ) : ?>
    

    【讨论】:

    • 我在哪里放置此代码?
    • 好的,但这是我的问题,我不知道在哪个文件中...我已将它放在具有以下代码的文件 woocommerce.php 中:&lt;?php get_header(); ?&gt;&lt;div id="main" class="row"&gt; &lt;?php if ( !function_exists('dynamic_sidebar') || !dynamic_sidebar("Shop Sidebar") ) : ?&gt;&lt;div class="col-lg-3"&gt;&lt;/div&gt;&lt;?php endif;?&gt; &lt;div id="content" class="col-lg-12 col-sm-6 col-md-6 col-xs-12"&gt;&lt;?php woocommerce_content(); ?&gt;&lt;/div&gt;&lt;/div&gt;&lt;?php get_footer(); ?&gt; 它显示在商店中页面,但在所有其他内容之前......并且在商店页面中。这种方式显示在产品页面中...
    【解决方案2】:

    例如在 header.php 上试试这个,你可以在你想要的地方添加侧边栏

    if ( is_active_sidebar( 'Sidebar' ) ) {
            dynamic_sidebar( 'Sidebar' );
    }
    

    【讨论】:

      猜你喜欢
      • 2023-03-13
      • 1970-01-01
      • 1970-01-01
      • 2015-01-31
      • 2018-04-17
      • 2013-08-09
      • 1970-01-01
      • 2018-07-01
      • 2011-04-14
      相关资源
      最近更新 更多