php – 如何显示Woocommerce类别描述
发布时间:2020-12-13 18:22:05 所属栏目:PHP教程 来源:网络整理
导读:我有常规的wordpress代码来显示类别描述: ?php echo category_description( $category_id ); ? 但是,我如何显示Woocommerce类别描述? @@ 在其中一条评论建议后,我补充道: ?php if ( have_posts() ) { while ( have_posts() ) { the_post(); global $post,
我有常规的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>'; } } ?> (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |