Woocommerce使边栏出现在页面的底部
问题描述:
我在非佑主题上安装了woocommerce,我希望能够在没有太大变化的情况下进行设计。但是当我安装它时,边栏显示在任何容器外(小部件显示在它们的div中,但没有包装)。现在我用Woocommerce使边栏出现在页面的底部
add_action('woocommerce_before_main_content', 'my_theme_wrapper_start', 10);
add_action('woocommerce_after_main_content', 'my_theme_wrapper_end', 10);
function my_theme_wrapper_start() {
echo '<section id="main">';
}
function my_theme_wrapper_end() {
echo '</section>';
}
从文档,这适用于woocommerce就好。但是我的侧边栏仍然处于底部,没有包装。是否还有一种方法可以将侧边栏包装起来,并将其放置在商店的内容旁边,只需使用挂钩,而不是将任何文件从插件中复制出来?
答
我想通了,这是一个“框架”为我的作品,如果有人需要它:
<?php
if (!function_exists('custom_open_woocommerce_content_wrappers')) {
function custom_open_woocommerce_content_wrappers(){
echo '<div class="container shop_container"><div class="row">';
}
}
if (!function_exists('custom_close_woocommerce_content_wrappers')) {
function custom_close_woocommerce_content_wrappers(){
echo '</div></div>';
}
}
if (!function_exists('custom_product_wrapper_open')) {
function custom_product_wrapper_open(){
echo '<div class="span8 content_with_right_sidebar">';
}
}
if (!function_exists('custom_product_wrapper_close')) {
function custom_product_wrapper_close(){
echo '</div>';
}
}
if (!function_exists('custom_before_shop_loop_sidebar')) {
function custom_before_shop_loop_sidebar() {
echo '<aside class="span4 sidebar sidebar_right">';
dynamic_sidebar(get_theme_mod('shop_sidebar', ''));
echo '</aside>';
}
}
add_action('woocommerce_after_shop_loop', 'custom_before_shop_loop_sidebar', 20);
if (!function_exists('custom_prepare_woocommerce_wrappers')) {
function custom_prepare_woocommerce_wrappers(){
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_before_shop_loop', 'woocommerce_output_content_wrapper', 10);
remove_action('woocommerce_after_shop_loop', 'woocommerce_output_content_wrapper_end', 10);
add_action('woocommerce_before_main_content', 'custom_open_woocommerce_content_wrappers', 10);
add_action('woocommerce_after_main_content', 'custom_close_woocommerce_content_wrappers', 10);
add_action('woocommerce_before_shop_loop', 'custom_product_wrapper_open', 10);
add_action('woocommerce_after_shop_loop', 'custom_product_wrapper_close', 10);
}
}
add_action('wp_head', 'custom_prepare_woocommerce_wrappers');
这将创建一个右边栏的包装。如果需要,您可以进一步对其进行自定义。希望能帮助到你。