【发布时间】:2023-03-30 11:00:02
【问题描述】:
我正在尝试从自定义分类创建以下菜单结构:
CAT 1
-SubCat1
-SubCat2
CAT 2
CAT 3
CAT 4
我想要实现的是当我点击一个子类别(例如 SubCat1)时,我当前的导航结构应该保持不变,并加粗当前的子类别。 当我点击另一个 PARENT 类别时,应该会出现它的子类别,并且只显示其余的父猫(不是所有有子猫的猫)。
我的问题如下:
我在单击父类别时管理了创建子导航菜单,但它仅在菜单中显示 CURRENT 和 CHILD LEVEL 类别,没有使用此代码的其他主要类别:
<?php
$taxonomy = $tax;
$orderby = 'name';
$show_count = 1; // 1 for yes, 0 for no
$pad_counts = 0; // 1 for yes, 0 for no
$hierarchical = 1; // 1 for yes, 0 for no
$title = '';
if (get_term_children($term->term_id, $tax) != null) {
$child = $term->term_id;
} else {
$child = '';
}
$args = array(
'taxonomy' => $taxonomy,
'orderby' => $orderby,
'show_count' => $show_count,
'pad_counts' => $pad_counts,
'hierarchical' => $hierarchical,
'title_li' => $title,
'child_of' => $child,
'current_category' => 0
);
?>
<? if (get_term_children($term->term_id, $tax) != null) { ?>
<h3><?php echo $term->name; ?> Templates</h3>
<? } ?>
<?php
wp_list_categories( $args ); ?>
问题在于上面的代码,当我点击一个子类别时,我的所有父/子类别都会再次显示。
我希望在浏览一个大类别中的任何子类别时能够保持相同的结构,并将粗体字体添加到我正在浏览的子类别中。
如果这对某人有意义,请提供帮助。
谢谢,
【问题讨论】:
标签: wordpress-theming wordpress