在模板中的特定父术语下显示自定义分类、子术语和帖子

时间:2015-06-23 作者:Faruk Hossain

我想在特定父术语下的模板中显示自定义分类法、子术语和帖子。

我需要的是:

Parent Taxonomy Term

-- Child Taxonomy Term

--- Post Type

--- Post Type

--- Post Type

1 个回复
SO网友:Anam Shah

这是工作代码。你可以试试你的

                $id = get_the_ID(false);
                $categories = get_the_category();
                $parents = array();
                $childs = array();
                foreach($categories as $cat){
                    if($cat->parent == 0){
                        $parents[] = $cat;
                    } else {
                        $childs[] = $cat;
                    }
                }
                $i = 1;
                echo "<div class=\'sub-container\'>";
                foreach($parents as $parent){
                    if($i>3){
                        $i=1;
                        echo "<div class=\'clr\'></div>";
                        echo "<hr class=\'mt25\'>";
                        echo "<div class=\'one3 gray-text mar-none\'>";
                    } else {
                        echo "<div class=\'one3 gray-text\'>";
                    }

                    echo "<h3 class=\'title fs14\'>".$parent->name."</h3>";
                    echo "<div class=\'fs10\'>";
                    foreach($childs as $child){
                        if($child->parent == $parent->cat_ID){
                            echo "<div class=\'fs14 child-cat\'><a href=".get_category_link( $child->cat_ID).">" . $child->name . "</a></div>";
                        }
                    }
                    echo "</div></div>";
                    $i++;
                }
                echo \'</div>\';

结束

相关推荐