【问题标题】:remove sidebar shop page woocommerce删除侧边栏商店页面 woocommerce
【发布时间】:2023-03-13 23:12:01
【问题描述】:

我一直在拼命寻求帮助。我真的很想只从我的 woocommerce 商店基本页面中删除侧边栏。在我的主题的管理选项中,有一个地方可以启用产品页面上的侧边栏,但您在那里选择的内容不仅会影响商店基本页面,还会影响所有存档页面。

在 archive-product.php 文件中,有代码根据该按钮是否启用来控制布局,所以我认为我最好的选择是使用 if else 语句来说明它是否是商店页面,使用“否” -侧边栏类。这是我想出的,但它不起作用。任何想法都会很棒。

<?php if ( is_object( $shop_page) ) : ?>
<div id="default_products_page_container" class="no-sidebar">
<?php elseif (have_posts() ) : ?>
<div id"default_products_page_container" class="with-sidebar">  

【问题讨论】:

    标签: php javascript woocommerce


    【解决方案1】:

    在您的子主题的functions.php中:

    // remove sidebar for woocommerce pages 
    add_action( 'get_header', 'remove_storefront_sidebar' );
    function remove_storefront_sidebar() {
        if ( is_shop() ) {
            remove_action( 'storefront_sidebar', 'storefront_get_sidebar', 10 );
        }
    }
    

    在 css 中,您必须将内容类更改为 100% 宽度,以用于我的主题:

     .post-type-archive-product .content-area {
        float: left;
        margin-left: 0;
        margin-right: 0;
        width: 100%;
    }
    

    【讨论】:

      【解决方案2】:

      要从您想在 function.php 文件中使用操作挂钩的商店页面中删除侧边栏 -

          add_action('woocommerce_before_main_content', 'remove_sidebar' );
          function remove_sidebar()
          {
              if ( is_shop() ) { 
               remove_action( 'woocommerce_sidebar', 'woocommerce_get_sidebar', 10);
             }
          }
      

      在这里你可以得到 WooCommerce Action 和 Filter Hook -https://docs.woothemes.com/wc-apidocs/hook-docs.html

      【讨论】:

        【解决方案3】:

        也许检查您正在使用的主题并从模板中删除侧边栏的代码。

        【讨论】:

        • 问题是我不知道如何仅从商店基本页面中删除侧边栏。由于商店页面的唯一模板也控制类别页面,如果我从模板中删除代码,它会影响其他“存档”页面。
        • 只需在基础页面上设置一个变量,并在包含侧边栏代码时检查是否是该页面
        【解决方案4】:

        删除侧边栏并使页面全宽。这个工作示例是正确的方法。

        1 - ID #secondary 是侧边栏 ID。我们将样式应用到#primary width:100%;,使页面充满

        2 - if(is_cart() || is_checkout() || is_product()) 行分别从购物车、结帐和产品页面中删除侧边栏。

        add_action('wp_head', 'hide_sidebar' ); 
        function hide_sidebar(){ 
          if(is_cart() || is_checkout() || is_product()){ 
          ?>
          <style type="text/css">
            #secondary {
                display: none;
            }
            #primary {
               width:100%;
            }
           </style>
          <?php
         }
        }
        

        【讨论】:

          【解决方案5】:

          我正在使用

          • WooCommerce 5.6.0
          • shopstore主题版本4.2.9

          我解决了修改脚本 inc/woocommerce.php

          中的 woocommerce 包装函数

          这里的变化:

          function shopstore_woocommerce_wrapper_before()
          

          我换了

          $arg = array( 'column' => 'col-md-8' );
          

          $sidebar_column = 'col-md-4 no-sidebar-actived';
          $column = 'col-md-12';
          $sidebar = 'inactive';
          $arg = array( 'section' => 'page-container', 'column' => $column, 'sidebar'=>$sidebar , 'sidebar_column' => $sidebar_column );
          

          function shopstore_woocommerce_wrapper_after()
          

          我换了

          $arg = array( 'sidebar' => 'active' );
          

          $arg = array( 'sidebar' => 'inactive' );
          

          所以,我在创建店铺页面时使用了与无侧边栏模板相同的策略(在脚本 custom-template/no-sidebar.php 中)。

          【讨论】:

            猜你喜欢
            • 2015-01-31
            • 2019-07-11
            • 1970-01-01
            • 2013-09-04
            • 2018-04-17
            • 2016-09-24
            • 2013-08-09
            • 1970-01-01
            • 2015-11-16
            相关资源
            最近更新 更多