删除侧边栏商店页面woocommerce

时间:2013-05-30 00:53:00

标签: php javascript woocommerce

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

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

<?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">  

4 个答案:

答案 0 :(得分:6)

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

答案 1 :(得分:1)

要从商店页面中移除侧边栏,您要在 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

答案 2 :(得分:0)

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

答案 3 :(得分:0)

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

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
 }
}
相关问题