0

我想在不同类别的单个产品页面上显示不同的内容。

示例代码

<?php if(in_category('62')){ ?>Text for category 62<?php }?>
<?php if(in_category('21')){ ?>Text for category 21<?php }?>
4

1 回答 1

0

制作新模板并将其命名为:taxonomy-product_cat-Your_category_product_slug.php

路径:/wp-content/your-theme/woocommerce/taxonomy-product_cat-Your_category_product_slug.php

另一种方法:

$cat1 = 62;
$cat2 = 21;

$terms = wp_get_post_terms($post->ID, 'product_cat');
if (!empty($terms)) {
    foreach ($terms as $t) {
        if ($t->term_id == $cat1) {
            woocommerce_get_template_part('single-product-product1');
        } else if ($t->term_id == $cat2) {
            woocommerce_get_template_part('single-product-product2');
        }
    }
}
于 2013-10-25T11:27:07.777 回答