我正在建立一个基于TwentyTwelve(子主题)的网站,我正在使用woocommerce。在我的商店页面(也是网站首页)上,我想删除侧边栏。
我想出了这个代码:
if(is_front_page() ){
remove_action( 'woocommerce_before_main_content', 'woocommerce_output_content_wrapper', 10);
remove_action( 'woocommerce_after_main_content', 'woocommerce_output_content_wrapper_end', 10);
remove_action( 'woocommerce_sidebar', 'woocommerce_get_sidebar', 10 );
add_action('woocommerce_before_main_content', 'twentytwelve_child_wrapper_start', 10);
add_action('woocommerce_after_main_content', 'twentytwelve_child_wrapper_end', 10);
function twentytwelve_child_wrapper_start() {
echo '<div id="shop">';
}
function twentytwelve_child_wrapper_end() {
echo '</div>';
}
}
它可以工作,但它删除了所有 woo 页面上的侧边栏(购物车和结帐页面除外)它应该在商店/首页(以及与此相关的搜索结果)
底线:我无法正确处理条件语句。请帮忙。因为我有点新手,请保持简单。提前谢谢。
你能用css而不是php吗? 如果您像这样定位首页的正文类:
body.frontpage .sidebar{
display:none;
}