wordpress - 如何在类别中制作类别中的类别
问题描述
我在 wordpress 有问题
我需要在类别中在类别中创建类别的方法
例子
我有类别有名称 bmw 在 xll 类别 1999 中有子类别 xll 在类别 1999 中有子类别零件和其他类别,如发动机等
所以我们有 4 级类别
我们如何做到这一点这是我的代码
<?php
$args = array(
'orderby' => 'name',
'taxonomy'=>'brand_category',
'parent' => 0
);
$categories = get_categories( $args );
if($categories->parent > 0){ ?>
<?php foreach ( $categories as $category ) { ?>
<li><a href="<?php echo get_category_link( $category->term_id );?>"><?php echo $category->name ;?></a></li>
<?php } ?>
<?php } else { ?>
<?php $queried_object = get_queried_object();
$term_ids = $queried_object->term_id;
$term_id = $term_ids;
$taxonomy_name = 'brand_category';
$term_children = get_term_children( $term_id, $taxonomy_name, $parent = $term->parent);
$parent = $term->parent;
?>
<?php foreach ( $term_children as $child ) {
$term = get_term_by( 'id', $child, $taxonomy_name );
echo '<li><a href="' . get_term_link( $child, $taxonomy_name ) . '">' . $term->name . '</a></li>';
}?>
<?php }?>
解决方案
推荐阅读
- c++ - 计算单词的出现次数
- python - Kivy:文本的定位
- android - 如何让 Jetpack Compose AndroidView 在新参数上运行新的 viewBlock 实例?
- flutter - 如何修复此错误类型'_InternalLinkedHashMap
' 不是类型 'FutureOr 的子类型 - >'
- php - php 数组列表 foreach 打印
- javascript - 如何获取数组对象并在另一个超链接网页上显示特定对象及其属性?
- java - 内容 Uri 使我的应用程序崩溃,但文件 Uri 正在运行
- python - 如何以这种方式均匀分布系列?
- django - Django 休息框架
- python - 对整数列表中的几个项目求和