此代码来自归档页面并列出所有带有特定标记的产品,请有人帮助我修改此代码,使列表产品仅来自当前类别:
<?php if ( is_product_tag() ) :?>
<?php do_action('woocommerce_before_shop_loop'); ?>
<ul class="products">
<?php while ( have_posts() ) : the_post(); ?>
<?php woocommerce_get_template_part( 'content', 'product'); ?>
<?php endwhile; // end of the loop. ?>
</ul>
<?php do_action('woocommerce_after_shop_loop'); ?>
<?php endif; ?>发布于 2012-11-06 16:18:15
要做到这一点,最好的办法是在特定的标记上添加一个过滤器/钩子。在WooCommerce API文档站点上看到这个片段,它排除了适当格式的类别,并朝着正确的方向发展。http://wcdocs.woothemes.com/snippets/exclude-a-category-from-the-shop-page/
但是,如果您希望以一种向下和肮脏的方式对这个内容部分的特定标记进行筛选,那么您可以在您的woocommerce_get_template_part()周围包装一个if。
<?php while ( have_posts() ) : the_post(); ?>
<?php if ( *** product has tag *** ) { ?>
<?php woocommerce_get_template_part( 'content', 'product'); ?>
<?php endif; ?>
<?php endwhile; // end of the loop. ?>您可以在http://wcdocs.woothemes.com/apidocs/class-WC_Product.html#_到达_标签查看产品标签上的API文档。
确保您在WooCommerce上遵循http://wcdocs.woothemes.com/codex/template-structure/主题自定义建议
除非您希望这是全局的,否则您必须考虑各种输出,并确定什么时候不想同时过滤产品和标签。
https://wordpress.stackexchange.com/questions/71726
复制相似问题