php 如何显示 Woocommerce 类别描述
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/19249756/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
How to display Woocommerce category description
提问by Oshrib
I have the regular wordpress code to display category description:
我有常规的 wordpress 代码来显示类别描述:
<?php echo category_description( $category_id ); ?>
But how can i display Woocommerce category description? @@ After one of the comment suggestion i added:
但是如何显示 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
?>
Still, not work.
还是不行。
回答by codepixlabs
$args = array( 'taxonomy' => 'product_cat' );
$terms = get_terms('product_cat', $args);
$count = count($terms);
if ($count > 0) {
foreach ($terms as $term) {
echo $term->description;
}
}
Edit for Last answer:
编辑最后一个答案:
<?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>';
}
}
回答by Swapnali
You can display the product category description-
您可以显示产品类别描述-
use this code -
使用此代码 -
<?php global $post, $product;
$categ = $product->get_categories();
$term = get_term_by ( 'name' , strip_tags($categ), 'product_cat' );
echo $term->description; ?>
回答by MarkPraschan
the_archive_description()
worked for my purposes when other (more complicated) solutions would not.
the_archive_description()
当其他(更复杂的)解决方案不起作用时,我的目的是有效的。
Optional before and after string parameters can be added if needed.
如果需要,可以添加可选的前后字符串参数。
回答by user2703913
The main answer for some reason displayed more than one description for me.
出于某种原因,主要答案为我显示了不止一种描述。
The answer below solved this for anyone with the same issue:
下面的答案为任何有同样问题的人解决了这个问题: