Woocommerce 使侧边栏出现在页面底部 [英] Woocommerce making sidebar appear at the bottom of the page

查看:30
本文介绍了Woocommerce 使侧边栏出现在页面底部的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在非 woo 主题上安装了 woocommerce,我希望对其进行样式设置,没有太大变化.但是当我安装它时,侧边栏显示在任何容器之外(小部件显示在它们的 div 中,但没有包装器).现在我用了

I installed woocommerce on a non woo theme, I wish to style it, without much change. But when I installed it, the sidebar is displayed out of any container (widgets are shown in their divs but without a wrapper). Now I used

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 就好了.但是我的侧边栏仍然在底部,没有包装.有没有办法包装侧边栏,并将其放在商店内容旁边,仅使用挂钩,而不是从插件中复制任何文件?

From the documentation, and this works for woocommerce just fine. But my sidebar is still at the bottom, without a wrapper. Is there a way to wrap the sidebar as well, and place it next the content of the shop, using just hooks, not copying any files out of the plugin?

推荐答案

我想通了,这是一个对我有用的框架",以防有人需要它:

I figured it out, this is a 'framework' that works for me, in case anybody needs it:

<?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' );

这将创建一个带有右侧边栏的包装器.如果需要,您可以进一步自定义它.希望有帮助.

This will create a wrapper with a right sidebar. You can customize it further if you need to. Hope it helps.

这篇关于Woocommerce 使侧边栏出现在页面底部的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆