【问题标题】:Woocommerce product filter displays dynamic productWoocommerce 产品过滤器显示动态产品
【发布时间】:2016-10-21 22:02:44
【问题描述】:

在 WooCommerce 中,我使用了 woocommerce 产品过滤器。当我刷新页面时,它会以随机顺序显示产品。

当我刷新产品页面时,谁能帮我弄清楚如何以相同的顺序显示相同的产品?

<?php global $wp_query;
    $cat = $wp_query->get_queried_object();
    $thumbnail_id = get_woocommerce_term_meta( $cat->term_id, 'thumbnail_id', true );
    $image = wp_get_attachment_url( $thumbnail_id ); ?>
    <?php if($image): ?>
        <?php if ( apply_filters( 'woocommerce_show_page_title', true ) ) : ?>
            <div class="interior-banner group" <?php if ( $image ) : ?>style="background:url(<?php echo $image;?>) no-repeat center;"<?php endif; ?>>
                <div class="background-mask">
                    <div class="content">
                        <h1 class="title"><?php woocommerce_page_title(); ?></h1>
                        <h2 class="sub-title"><?php echo get_cat_name($cat->parent);?></h2>
                    </div>
                </div>
            </div>
            <?php if($cat->description): ?>
                <div class="interior-banner-description">
                    <div class="content">
                        <p class="description"><?php echo $cat->description; ?></p>
                    </div>
                </div>
            <?php endif;?>
        <?php endif;?>
    <?php endif;?>
    <div class="woocommerce-child-cat">
    <?php woocommerce_breadcrumb(); ?>

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

        <div class="child-cat-cover group ">
            <div class="left-column">
                <?php
                    global $wp_query;
                    $cat = $wp_query->get_queried_object();
                    //product filter
                    echo '<h4 class="cat-title">'.$cat->name.'</h4>';
                    echo do_shortcode('[woof sid="product-filter" is_ajax=1 taxonomies=product_cat:'. $cat->term_id .']');
                ?>
            </div>
            <div class="right-column">
                <?php echo do_shortcode('[woof_products per_page=12 columns=3 is_ajax=1 taxonomies=product_cat:'. $cat->term_id .']'); ?>
            </div>
        </div>

        <?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; ?>
    </div>

【问题讨论】:

    标签: wordpress woocommerce


    【解决方案1】:

    您可以使用“pre_get_post”钩子修改查询,并将“post_order”添加到产品存档页面pre_get_post doc上的查询中 如果您想更具体地了解查询修改的效果,请仅对 product_archive 页面使用条件标签。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2017-06-14
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2014-10-17
      • 1970-01-01
      • 2021-01-17
      • 1970-01-01
      相关资源
      最近更新 更多