首页 > 解决方案 > 如何在类别中制作类别中的类别

问题描述

我在 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 }?>

标签: wordpress

解决方案


推荐阅读