2015-06-22 33 views

回答

2

试试这个:

global $post; 
$terms = get_the_terms($post->ID, 'product_cat'); 
foreach ($terms as $term) { 
    echo $term->name .' '; 
    $thumbnail_id = get_woocommerce_term_meta($term->term_id, 'thumbnail_id', true); 

    $image = wp_get_attachment_url($thumbnail_id); 

    echo "'{$image}'"; 
} 
+0

它的工作原理,谢谢 –

+0

在归档product.php我用了一个背景与类别图像(使用此方法http://stackoverflow.com/questions/30918268/how-can-i-set-the-image-of -woocommerce-category-as-the-background-of-the-categor),是否可以在single-product.php中使用类别图像? –

+0

是的,你可以使用该代码,你有termid,所以你可以得到缩略图。 –

0

找到content-single-product-CATEGORYNAME.php

woocommerce_get_template_part('content', 'single-product'); 

更改为:

if (is_product_category('CATEGORYNAME') { 
woocommerce_get_template_part('content', 'single-product-CATEGORYNAME'); 
}else{ 
woocommerce_get_template_part('content', 'single-product'); 
} 
相关问题