簡體   English   中英

刪除側邊欄商店頁面woocommerce

[英]remove sidebar shop page woocommerce

我一直在拼命地尋求幫助。 我真的很想只從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">  

在您的子主題的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%;
}

要從商店頁面刪除邊欄,您要在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行動和篩選器掛鈎- https://docs.woothemes.com/wc-apidocs/hook-docs.html

也許檢查出您正在使用的主題,然后從模板中刪除側邊欄的代碼。

移除邊欄,使頁面全寬。 這個工作示例是正確的方法。

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
 }
}

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM