【问题标题】:How to get related category/categories in WordPress archive page如何在 WordPress 存档页面中获取相关类别/类别
【发布时间】:2015-07-29 21:10:12
【问题描述】:

我在 WordPress 中使用 WooCommerce。我有几个这样的产品类别,

示例:

Product 1 Category (//parent)
-- Category 1
-- Category 2
-- Category 3
-- Category 4
Product 2 Category (//parent)
-- Category 10
-- Category 11
-- Category 12
-- Category 13

如果我在类别 2(子)的存档页面中,我如何将父类别(产品 1 类别)下的所有其他类别名称作为列表获取。

【问题讨论】:

标签: php wordpress woocommerce


【解决方案1】:

我解决了这个问题。

<?php 
$terms = get_the_terms( $post->cat_ID , 'product_cat' );
foreach ($terms as $term) { 
    $term_id = $term->term_id;
    $term_link = get_term_link( $term, $taxonomy );
    $term_name = $term->name;
    echo '<a class="cat-box" href="' . $term_link . '"><span class="cat-name">' . $term_name . '</span></a>';   
}
?>

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2015-05-14
    • 2014-11-24
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-11-28
    相关资源
    最近更新 更多