如何在woocommerce存档产品页面上按标签或类别显示产品

时间:2016-10-31 14:07:26

标签: wordpress woocommerce

请帮我定制我的woocommerce产品循环,按标签或类别显示产品。我在归档产品页面上的自定义循环看起来像这样,它排除了一个类别:

<?php
                $product = new WC_Product(get_the_ID());
                $params = array('posts_per_page' => 12, 'post_type' => 'product', 'tax_query' => array(
        array(
            'taxonomy' => 'product_cat',
            'field' => 'slug',
            'terms' => array( 'free' ),
            'operator' => 'NOT IN'
        )
    ));
                $wc_query = new WP_Query($params);
                ?>
                <?php if ($wc_query->have_posts()) : ?>
                <?php while ($wc_query->have_posts()) :
                $wc_query->the_post(); ?>
                <article class="portfolio__item portfolio__item--shop">
                    <figure class="blog__image-container">
                        <?php if ( has_post_thumbnail()) {the_post_thumbnail('thumb-blog' ,array("class"=>"portfolio__image post_thumbnail"));} ?>
                    </figure>
                    <h3 class="portfolio__content-title portfolio__content-title--shop"><?php the_title(); ?></h3>
                    <p class="portfolio__content-text portfolio__content-text--shop"><?php $product = new WC_Product(get_the_ID()); echo $product->get_price_html(); ?></p>
                        <div class="portfolio__content">
                            <img class="portfolio__content-image" src="<?php echo get_template_directory_uri(); ?>/img/link-loop.png" alt="" data-jslghtbx="<?php
                                $thumb_id = get_post_thumbnail_id();
                                $thumb_url = wp_get_attachment_image_src($thumb_id,'thumb-big', true);
                                echo $thumb_url[0];
                            ?>">
                            <a href="?add-to-cart=<?php echo $product->id; ?>" class="portfolio__link">
                                <p class="portfolio__content-text">Click to buy</p>
                            </a>
                        </div>

                </article>
                <?php endwhile; ?>

它位于http://test.art-electrik.ru/wrap/dark/wordpress/portfolio/ 我需要按标签http://test.art-electrik.ru/wrap/dark/wordpress/product-tag/ads/排序此页面,但现在它显示所有产品。

0 个答案:

没有答案