带有父头的自定义文本分类类子类别列表

时间:2017-04-10 作者:Fahem Ahmed

您好,我只想在父目录下创建一个自定义子类别列表,父目录作为标题,如下所示enter image description here

1 个回复
最合适的回答,由SO网友:Fahem Ahmed 整理而成

我刚得到一个这样的解决方案>>

                        <?php 

                        $taxonomyName = "com_category";
                        $parent_terms = get_terms($taxonomyName, array(\'parent\' => 0, \'orderby\' => \'slug\', \'hide_empty\' => false));   

                        foreach ($parent_terms as $pterm) {
                            $terms = get_terms($taxonomyName, array(\'parent\' => $pterm->term_id, \'orderby\' => \'slug\', \'hide_empty\' => false));
                            foreach ($terms as $term) {
                                echo \'<div class="single_cat col-md-3">\';
                                echo \'<h3>\'.$pterm->name.\'</h3>\'; 
                                echo "<ul>";
                                echo \'<li><a href="\' . get_term_link( $term->name, $taxonomyName ) . \'">\' . $term->name . \'</a></li>\'; 
                                echo "</ul>";
                                echo \'</div>\'; 
                            }
                        }


                         ?>