我在WordPress中使用WooCommerce。我有几类这样的产品,
Example:
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类别)下的所有其他类别名称作为列表。
我在尝试什么
$args = array(
\'hierarchical\' => 1,
\'show_option_none\' => \'\',
\'hide_empty\' => 0,
\'parent\' => $parent_cat_ID,
\'taxonomy\' => \'product_cat\'
);
$subcats = get_categories($args);
echo \'<ul class="wooc_sclist">\';
foreach ($subcats as $sc) {
$link = get_term_link( $sc->slug, $sc->taxonomy );
echo \'<li><a href="\'. $link .\'">\'.$sc->name.\'</a></li>\';
}
echo \'</ul>\';
}
Out put should :
.Category 1
.Category 2
.Category 3
.Category 4
我使用了下面的代码,它在单个产品中运行良好。php页面-
<?php
$parent = get_category_parents( $cat, true, \' » \' );
echo $product->get_categories( \', \', \'<span>\' . _n( \'Category:\', \'Categories:\', sizeof( get_the_terms( $post->ID, \'product_cat\' ) ), \'woocommerce\' ) . \' \', \'.</span>\' );
?>