0

我目前正在使用WOOCOMMERCE V2.0.13 并且我正在尝试显示当前产品类别中的每个产品(例如,在建筑页面上时的建筑产品),我已经设法显示当前类别中的单个产品但如果产品也属于另一个类别(例如建筑和环境),则当前类别会中断并显示来自建筑或环境的零产品。

如果我能在显示当前类别的产品方面获得一些建议/帮助,并允许它与多个类别的产品一起使用,我会非常感谢帮助和时间。

我很高兴重新编码整个部分以使其正常工作,这是我的代码,如果我错过了任何内容,请告诉我。

谢谢你。

<ul class="products"> 
    <?php
        global $post, $product;
        $categ = $product - > get_categories();
        $categ2 = preg_replace('/<a href=\"(.*?)\">(.*?)<\/a>/', "\\2", $categ); 
    ?> 
    <?php
        global $product;
        $args = array('post_type' = > 'product', 'posts_per_page' = > '999', 'product_cat' = > $categ2, );
        $loop = new WP_Query($args);
        while ($loop - > have_posts()): $loop - > the_post();
        global $product; 
    ?> 
        <li>
            <a href = "<?php echo get_permalink(); ?>"> 
                <?php
                    if (has_post_thumbnail()) {
                        $image = get_the_post_thumbnail($post - > ID, apply_filters('single_product_large_thumbnail_size', 'shop_single'));
                        $image_title = esc_attr(get_the_title(get_post_thumbnail_id()));
                        $image_link = get_permalink($product_id);
                        $attachment_count = count($product - > get_gallery_attachment_ids());
                        echo apply_filters('woocommerce_single_product_image_html', sprintf('<a href="%s" itemprop="image" class="woocommerce-main-image zoom" title="%s"  rel="prettyPhoto'.$gallery.'">%s</a>', $image_link, $image_title, $image), $post - > ID);
                    } else {
                        echo apply_filters('woocommerce_single_product_image_html', sprintf('<img src="%s" alt="Placeholder" />', woocommerce_placeholder_img_src()), $post - > ID);
                } ?> 
            </a>
            <div>
                <h3>
                    <a href="<?php echo get_permalink(); ?>"><?php the_title();?></a> 
                    <span> 
                        <?php
                            if ($price_html = $product - > get_price_html()) { 
                        ?> 
                            <span class = "price">
                                <?php echo $price_html; ?>
                            </span> 
                        <?php } ?>
                    </span> 
                </h3>
            </div> 
            <div> 
                <p> 
                    <?php
                        $excerpt = get_the_excerpt();
                        echo string_limit_words($excerpt, 15); 
                    ?> 
                </p>
            </div> 
        </li>
    <?php endwhile; ?>
</ul>

截屏

4

1 回答 1

0
 <?php if ( have_posts() ) : ?>
        <?php woocommerce_product_loop_start(); ?>
        <?php woocommerce_product_subcategories(); ?>
            <div class="courses-main">
                <ul class="products">
                    <?php while ( have_posts() ) : the_post(); ?>
                        <li>   
                            <a href="<?php echo get_permalink(); ?>">
                                <?php
                                    if ( has_post_thumbnail() ) {
                                        $image = get_the_post_thumbnail( $post->ID, apply_filters( 'single_product_large_thumbnail_size', 'shop_single' ) );
                                        $image_title = esc_attr( get_the_title( get_post_thumbnail_id() ) );
                                        $image_link = get_permalink( $product_id );
                                        $attachment_count   = count( $product->get_gallery_attachment_ids() );
                                        echo apply_filters( 'woocommerce_single_product_image_html', sprintf( '<a href="%s" itemprop="image" class="woocommerce-main-image zoom" title="%s"  rel="prettyPhoto' . $gallery . '">%s</a>', $image_link, $image_title, $image ), $post->ID );
                                    } else {
                                        echo apply_filters( 'woocommerce_single_product_image_html', sprintf( '<img src="%s" alt="Placeholder" />', woocommerce_placeholder_img_src() ), $post->ID );
                                    }
                                ?>
                            </a>
                            <div>
                                <h3>
                                    <a href="<?php echo get_permalink(); ?>"><?php the_title();?></a>
                                        <span>
                                            <?php if ( $price_html = $product->get_price_html()) { ?>
                                                <span class="price"><?php echo $price_html; ?></span> 
                                            <?php } ?>
                                        </span>
                                 </h3>
                            </div>
                            <div>
                                <p>
                                    <?php
                                        $excerpt = get_the_excerpt();
                                        echo string_limit_words($excerpt,15);
                                    ?>
                                </p>
                            </div>
                        </li>
                <?php endwhile;?>
            </ul>
        </div>
        <?php woocommerce_product_loop_end(); ?>
    <?php endif; ?>
于 2013-08-30T14:59:46.720 回答