[英]How to get all categories on a category page - category.php - when using multiple categories in Wordpress?
[英]How to get related category/categories in WordPress archive page
我在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(sub)的存檔頁面中,如何獲得父類別(產品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>';
}
?>
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.