首页 文章

Woocommerce侧边栏不到位

提问于
浏览
0

enter image description here

这是我在woocommerce开发的网站 . 边栏不会仅显示在类别页面右侧的类别页面上 . 在产品页面上它显示正常 .

用于显示产品档案的模板,包括作为帖子类型档案的主店铺页面 .

通过将此模板复制到yourtheme / woocommerce / archive-product.php来覆盖此模板

<?php
    /**
     * woocommerce_before_main_content hook
     *
     * @hooked woocommerce_output_content_wrapper - 10 (outputs opening divs for the content)
     * @hooked woocommerce_breadcrumb - 20
     */
    do_action( 'woocommerce_before_main_content' );
    remove_action( 'woocommerce_before_shop_loop', 'woocommerce_catalog_ordering', 30 );
?>

    <?php if ( apply_filters( 'woocommerce_show_page_title', true ) ) : ?>

        <h1 class="page-title"><?php woocommerce_page_title(); ?></h1>

    <?php endif; ?>

    <?php do_action( 'woocommerce_archive_description' ); ?>

    <?php if ( have_posts() ) : ?>

        <?php
            /**
             * woocommerce_before_shop_loop hook
             *
             * @hooked woocommerce_result_count - 20
             * @hooked woocommerce_catalog_ordering - 30
             */
            do_action( 'woocommerce_before_shop_loop' );
        ?>

        <?php woocommerce_product_loop_start(); ?>

            <?php woocommerce_product_subcategories(); ?>

            <?php while ( have_posts() ) : the_post(); ?>

                <?php wc_get_template_part( 'content', 'product' ); ?>

            <?php endwhile; // end of the loop. ?>

        <?php woocommerce_product_loop_end(); ?>

        <?php
            /**
             * woocommerce_after_shop_loop hook
             *
             * @hooked woocommerce_pagination - 10
             */
            do_action( 'woocommerce_after_shop_loop' );
        ?>

    <?php elseif ( ! woocommerce_product_subcategories( array( 'before' => woocommerce_product_loop_start( false ), 'after' => woocommerce_product_loop_end( false ) ) ) ) : ?>

        <?php wc_get_template( 'loop/no-products-found.php' ); ?>

    <?php endif; ?>

<?php
    /**
     * woocommerce_after_main_content hook
     *
     * @hooked woocommerce_output_content_wrapper_end - 10 (outputs closing divs for the content)
     */
    do_action( 'woocommerce_after_main_content' );
?>

<?php
    /**
     * woocommerce_sidebar hook
     *
     * @hooked woocommerce_get_sidebar - 10
     */
    do_action( 'woocommerce_sidebar' );
?>

2 回答

  • 1

    问题是你的div元素结构 . 尝试对模板中每个div的开启和关闭进行排序 . Headers 为 Headers ,内容为内容,侧边栏为侧边栏,页脚为页脚div元素 .

  • 1

    您使用的是Woocommerce主题,自定义构建还是其他主题?

    我建议检查内容包装器是否仍然与其他页面相同 . Woocommerce想要使用自己的包装div . 例如 . 在大多数页面上,您可能有以下包装:

    <div id="primary">
         <!-- ... Main content of your site -->
    </div><!-- #primary -->
    

    Woocommerce可能会覆盖这一点:

    <div id="container"><div id="content" role="main">
    

    要将此副本 wrapper-start.phpwrapper-end.php 修复为 yourtheme/woocommerce/global/ ,然后修复相应文件中的打开和关闭div .

    你也可以在 /loop/ 看看 loop-start.phploop-end.php

    或者您可以尝试取消包装并添加自己的包装:

    remove_action( 'woocommerce_before_main_content', 'woocommerce_output_content_wrapper', 10 );
    remove_action( 'woocommerce_before_main_content', 'woocommerce_output_content_wrapper_end', 10 );
    add_action( 'woocommerce_before_main_content', 'add_content_inner_wrapp', 10, 1 );
    add_action( 'woocommerce_after_main_content', 'close_content_inner_wrap', 10, 1 );
    function add_content_inner_wrapp(){
    ?>
        <div id="container">
            <div id="content-inner">
    <?php   
    }
    function close_content_inner_wrap(){
    ?>
            </div><!-- #content-inner-->
        </div><!-- #container-->
    <?php   
    }
    

    希望有所帮助 .

相关问题