php - 在 Woocommerce 产品类别存档页面中获取当前术语名称
问题描述
我正在尝试获取产品类别存档页面的单个产品类别名称。
使用此代码:
$categ = $product->get_categories();
echo $categ;
它还显示了所有父类别……</p>
如何在 Woocommerce 产品类别存档页面中获取当前术语名称?
解决方案
要获取当前产品类别存档页面的产品类别术语名称,您将使用:
// 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>';
}
测试和工作。
推荐阅读
- c# - 如何在 C# 中解决此问题: main.cs(18,5): 警告 CS0642: 可能错误的空语句
- python - 嵌套字典的自动激活,其中包含要在 Python 中附加的列表
- websphere - 在哪里可以找到 com.ibm.websphere.runtime.CustomService 现有服务的配置详细信息?
- javascript - 我应该将预加载器图像放在页面加载的哪个位置?
- proc-r-package - 与 AUC 的 pROC 测试差异 = 0.5
- c - 为什么我的代码不倒带并将输入保留在缓冲区中?
- python - 我如何从互联网上随机拍摄一张照片(从关键字的结果中),然后让 python 显示给我看?
- javascript - Spark AR - 启用从脚本到补丁编辑器的动画
- java - 根据预定义的规则集将输入集分类
- angular - 如何将布尔值从服务发送到可观察的组件?(Angular)