Wordpress 以三列显示自定义分类法,从第一个子项开始

Wordpress 以三列显示自定义分类法,从第一个子项开始,wordpress,foreach,custom-post-type,taxonomy,custom-taxonomy,Wordpress,Foreach,Custom Post Type,Taxonomy,Custom Taxonomy,我有一个三层的分类结构,名为“服务税”: 母公司 -孩子 --孙子 --孙子 我试图显示与当前自定义帖子关联的所有分类法,并将它们作为列divs三分之一进行回显,而不是像这样显示第一个父级: -孩子 --孙子 --孙子 我在下面使用的代码是我所能得到的,但是,在get_中使用get_术语,每个循环的get_术语就是获取与帖子无关的术语 <div class="three-column cf"> <?php $myterm = 'services_tax'; $terms =

我有一个三层的分类结构,名为“服务税”:

母公司 -孩子 --孙子 --孙子

我试图显示与当前自定义帖子关联的所有分类法,并将它们作为列divs三分之一进行回显,而不是像这样显示第一个父级:

-孩子 --孙子 --孙子

我在下面使用的代码是我所能得到的,但是,在get_中使用get_术语,每个循环的get_术语就是获取与帖子无关的术语

<div class="three-column cf">
<?php
$myterm = 'services_tax';
$terms = get_the_terms( get_the_ID(), $myterm );
if ( $terms ) :
?>
    <?php $i = 0; ?>
    <?php foreach ( $terms as $term ) : ?>
        <?php if ( $term->parent == 0 ) : ?>
            <?php
            $subargs = array(
                'orderby' => 'name',
                'order' => 'ASC',
                'hide_empty' => true,
                'hierarchical' => true,
                'child_of' => $term->term_id,
                'parent' => $term->term_id
            );
            $children = get_terms( $myterm, $subargs );
            ?>
            <?php if( $children ) : //if it has sub-categories ?>
                <?php foreach( $children as $child ) : ?>
                    <?php if ( $i != 0 && $i % 3 == 0 ) : ?>
                        </div><!-- .three-column -->
                        <div class="three-column cf">
                    <?php endif; ?>
                    <div class="third">
                        <?php //var_dump($i); ?>
                        <h4 class="h3"><?php echo $child->name; ?></h4><!-- .h3 -->
                        <?php
                        $subsubargs = array(
                            'orderby' => 'name',
                            'order' => 'ASC',
                            'hide_empty' => true,
                            'hierarchical' => true,
                            'child_of' => $child->term_id,
                            'parent' => $child->term_id
                        );
                        $sub_children = get_terms( $myterm, $subsubargs );
                        ?>
                        <?php if( $sub_children ) : //if it has sub-sub-categories ?>
                            <ul>
                                <?php foreach( $sub_children as $sub_child ) : ?>
                                    <li><?php echo $sub_child->name; ?></li>
                                <?php endforeach; ?>
                            </ul>
                        <?php endif; ?>
                    </div><!-- .third -->
                    <?php $i++; ?>
                <?php endforeach; ?>
            <?php endif; ?>
        <?php endif; ?>
    <?php endforeach; ?>
<?php endif; ?>
我已经阅读了我所能找到的所有没有运气的问题/答案

是最有帮助的


如果我能用get_,the,the,the,the,the,the,the,the,the,the,the,the,the,the,get,the,the,the,the,the,the,get,the,the,the,the,get,the,the,the,the,the,the,the,the。我感到非常困惑,任何帮助都将不胜感激。

我想我刚刚想好了,使用wp\u get\u post\u术语而不是foreach中的get\u术语。

那么,你没有得到父分类法吗?