0
在WooCommerce循环内显示瓦片正下方的产品类别可以吗?Woocommerce - 在回路中显示类别
这里有一个代码,我已经包含在mytheme/woocommerce/content-product.php
,取自Wordpress documentation on get_the_category()
;但它似乎没有输出任何东西
<a href="<?php the_permalink(); ?>" class="titulo-insumo" title="<?php the_title(); ?>">
<?php the_title(); ?>
</a>
<div class="label-group"><!--Categories *should* be outputed here -->
<?php
$categories = get_the_category();
$separator = ' ';
$output = '';
if($categories){
foreach($categories as $category) {
$output .= '<a href="'.get_category_link($category->term_id).'" class="label bg-terciary" title="' . esc_attr(sprintf(__("Ver todos los artículos en la categoría %s"), $category->name)) . '">'.$category->cat_name.'</a>'.$separator;
}
echo trim($output, $separator);
}
?>
</div>