<?php
// 获取主分类 "News" 的信息(通过slug获取,确保与您的站点结构一致)
$parent_category = get_term_by('slug', 'news', 'category');
if ($parent_category) : ?>
<h3 class="widget-title">
<span>
<a href="<?php echo esc_url(get_category_link($parent_category->term_id)); ?>">
<?php echo esc_html($parent_category->name); ?>
</a>
</span>
</h3>
<ul>
<?php
// 查询主分类下的子分类(深度为1,仅显示直接子分类)
$child_categories = get_categories(array(
'parent' => $parent_category->term_id,
'depth' => 1,
'orderby' => 'name',
'hide_empty' => false
));
foreach ($child_categories as $child_category) : ?>
<li class="cat-item cat-item-<?php echo esc_attr($child_category->term_id); ?>">
<a href="<?php echo esc_url(get_category_link($child_category->term_id)); ?>">
<?php echo esc_html($child_category->name); ?>
</a>
<span class="plus-minus"></span> <!-- 加减号图标容器 -->
</li>
<?php endforeach; ?>
</ul>
<?php endif; ?>
</section>
<?php
// 调用页脚侧边栏(支持多个小工具并列显示)
if ( is_active_sidebar( 'primary-abouts-sidebar' ) ) {
dynamic_sidebar( 'primary-abouts-sidebar');
}
?>
实现如下样式