我有常规的wordpress代码来显示类别描述:
<?PHP echo category_description( $category_id ); ?>
但是,我如何显示Woocommerce类别描述?
@@
在其中一条评论建议后,我补充道:
<?PHP if ( have_posts() ) { while ( have_posts() ) { the_post(); global $post,$product; $categ = $product->get_categories(); $term = get_term_by ( 'name',strip_tags($categ),'product_cat' ); echo $term->description; } // end while } // end if ?>
不过,不行.
$args = array( 'taxonomy' => 'product_cat' ); $terms = get_terms('product_cat',$args); $count = count($terms); if ($count > 0) { foreach ($terms as $term) { echo $term->description; } }
编辑最后答案:
<?PHP global $post; $args = array( 'taxonomy' => 'product_cat',); $terms = wp_get_post_terms($post->ID,'product_cat',$args); $count = count($terms); if ($count > 0) { foreach ($terms as $term) { echo '<div style="direction:rtl;">'; echo $term->description; echo '</div>'; } } ?>