如何显示与页面标题相关的woocommerce产品?

时间:2020-02-10 23:19:31

标签: php wordpress woocommerce

当前在我的wordpress网站上,我有成千上万的woocommerce产品(不带索引),当用户/漫游器输入按页面标题过滤的页面时,我希望它们自动显示在普通页面中。到目前为止,我仅找到了通过过滤将以各种方式显示的产品来在页面上显示产品的方法,但没有一种通过页面标题来进行显示的方法。我是新来的(以防万一尚未注意到)。如果有人可以帮助我,我将永远感激不已。

我将代码留在这里:


<?php $args = array( 'post_type' => 'product', 'posts_per_page' => 10 );
        $loop = new WP_Query( $args );
        while ( $loop->have_posts() ) : $loop->the_post(); global $product; ?>

                <span class="product">    
                    <a href="<?php echo get_permalink( $loop->post->ID )  ?>" title="<?php echo esc_attr($loop->post->post_title ? $loop->post->post_title : $loop->post->ID); ?>" target="blank">
                        <?php woocommerce_show_product_sale_flash( $post, $product ); ?>


                        <?php if (has_post_thumbnail( $loop->post->ID )) echo get_the_post_thumbnail($loop->post->ID, 'shop_catalog'); else echo '<img src="'.woocommerce_placeholder_img_src().'" alt="Placeholder" width="300px" height="300px" />'; ?>
                        <h3><?php the_title(); ?></h3>
                        <span class="price"><?php echo $product->get_price_html(); ?></span>                    
                    </a>
                    <?php woocommerce_template_loop_add_to_cart( $loop->post, $product ); ?>
                </span>
    <?php endwhile; ?>
    <?php wp_reset_query(); ?>
</ul>

0 个答案:

没有答案