javascript 删除侧边栏商店页面woocommerce
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/16826241/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
remove sidebar shop page woocommerce
提问by Jenile Brooks
I've been desperately searching for help with this. I would really love to remove the sidebar only from my woocommerce shop base page. In the admin options for my theme there's a place to enable the sidebar on the product page but what you select there impacts not just the shop base page but all of the archive pages.
我一直在拼命寻求这方面的帮助。我真的很想从我的 woocommerce 商店基本页面中删除侧边栏。在我的主题的管理选项中,有一个地方可以在产品页面上启用侧边栏,但您在那里选择的内容不仅会影响商店基本页面,还会影响所有存档页面。
Within the archive-product.php file there's code that controls the layout based on if that button is enabled so I thought my best bet would be to use an if else statement to say if its the shop page, use the 'no-sidebar' class. This is what I came up with but it's not working. Any thoughts would be fantastic.
在 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">
回答by Iggy
In functions.php of your child theme:
在您的子主题的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 );
}
}
and in css you'll have to change content class to be 100% width, for my theme:
在 css 中,对于我的主题,您必须将内容类更改为 100% 宽度:
.post-type-archive-product .content-area {
float: left;
margin-left: 0;
margin-right: 0;
width: 100%;
}
回答by Swapnali
To remove sidebar from the shop page you want to use action hook in function.phpfile -
要从商店页面中删除侧边栏,您要在function.php文件中使用操作挂钩 -
add_action('woocommerce_before_main_content', 'remove_sidebar' );
function remove_sidebar()
{
if ( is_shop() ) {
remove_action( 'woocommerce_sidebar', 'woocommerce_get_sidebar', 10);
}
}
Here you can get WooCommerce Action and Filter Hook -https://docs.woothemes.com/wc-apidocs/hook-docs.html
在这里您可以获得 WooCommerce 操作和过滤器挂钩 - https://docs.woothemes.com/wc-apidocs/hook-docs.html
回答by Stas Jaro
Maybe check out the theme you are using and remove the code for the sidebar from the template.
也许检查您正在使用的主题并从模板中删除侧边栏的代码。
回答by jayashan perera
Remove the sidebar and make the page full width. This working example is the correct way to do it.
删除侧边栏并使页面全宽。这个工作示例是正确的方法。
1 - The ID #secondary
is the sidebar ID. Make the page full with we apply style to #primary width:100%;
1 - ID#secondary
是侧边栏 ID。使页面充满我们应用样式#primary width:100%;
2 - The line if(is_cart() || is_checkout() || is_product())
removes the sidebar from cart, checkout, and product pages respectively.
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
}
}