【问题标题】:WordPress custom taxonomy parent-child navigation menuWordPress自定义分类父子导航菜单
【发布时间】: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


    【解决方案1】:

    我要做的是创建一个自定义查询来循环使用0 的父级的分类,然后在显示它们的循环中执行get_term_children 函数。我相信这是创造这样的东西的最佳方式。这就是我在插件中所做的,它让我可以进行更多的自定义。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2014-02-26
      • 1970-01-01
      • 2015-04-04
      • 2014-02-16
      • 2019-09-08
      • 1970-01-01
      • 2017-08-31
      相关资源
      最近更新 更多