首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >列出当前类别的产品

问列出当前类别的产品
EN

WordPress Development用户
提问于 2012-11-06 14:21:52
回答 1查看 1.7K关注 0票数 0

此代码来自归档页面并列出所有带有特定标记的产品,请有人帮助我修改此代码,使列表产品仅来自当前类别:

代码语言:javascript
复制
<?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; ?>
EN

回答 1

WordPress Development用户

回答已采纳

发布于 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。

代码语言:javascript
复制
<?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/主题自定义建议

除非您希望这是全局的,否则您必须考虑各种输出,并确定什么时候不想同时过滤产品和标签。

票数 0
EN
页面原文内容由WordPress Development提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://wordpress.stackexchange.com/questions/71726

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档