【发布时间】:2021-01-09 01:15:12
【问题描述】:
我正在尝试在侧边栏中显示当前页面的类别及其子类别。标题应该是当前类别的名称并链接到当前类别。在侧边栏中可以看到我正在尝试实现的示例:https://food52.com/shop/pantry
以我目前的网站为例:https://farmtofrank.wpengine.com/product-category/prepared-foods/
这是我目前创建的代码:
<?php
$terms = get_terms([
'taxonomy' => get_queried_object()->taxonomy,
'parent' => get_queried_object_id(),
]);
global $post;
$terms = get_the_terms( $post->ID, 'product_cat' );
echo '<div>';
foreach ( $terms as $term) {
echo '<p class="filters"><a href="' . get_term_link( $term ) . '">' . $term->name . '</a></p>';
}
echo '</div>';
?>
它可以工作,但它将父链接放在列表的底部。如何将父链接保持在子类别上方的顶部?
【问题讨论】:
标签: php html wordpress woocommerce taxonomy-terms