【发布时间】:2018-12-09 10:43:39
【问题描述】:
我正在尝试获取产品类别存档页面的单个产品类别名称。
使用此代码:
$categ = $product->get_categories();
echo $categ;
它也显示了所有的父类别……
如何在 Woocommerce 产品类别存档页面中获取当前术语名称?
【问题讨论】:
标签: php wordpress woocommerce custom-taxonomy
我正在尝试获取产品类别存档页面的单个产品类别名称。
使用此代码:
$categ = $product->get_categories();
echo $categ;
它也显示了所有的父类别……
如何在 Woocommerce 产品类别存档页面中获取当前术语名称?
【问题讨论】:
标签: php wordpress woocommerce custom-taxonomy
要获取当前产品类别存档页面的产品类别术语名称,您将使用:
// Only on product category archive pages
if(is_product_category()){
// The WP_Term object for the current product category
$term = get_queried_object();
// Get the current term name for the product category page
$term_name = $term->name;
// Test output
echo $term->name . '<br>';
}
经过测试并且有效。
【讨论】: