WordPress子类别未显示

WordPress子类别未显示,wordpress,parent-child,parent,categories,Wordpress,Parent Child,Parent,Categories,如果试图让Wordpress浏览基于父标题的子标题列表,但它只能浏览一个或两个标题。有什么建议吗 代码如下 function get_categories_list() { $parent = $child = array(); foreach (get_the_category(get_the_id()) as $cat) { if ($cat->id === 0) { continue; } if

如果试图让Wordpress浏览基于父标题的子标题列表,但它只能浏览一个或两个标题。有什么建议吗

代码如下

function get_categories_list() {
    $parent = $child = array();
    foreach (get_the_category(get_the_id()) as $cat) {
        if ($cat->id === 0) {
            continue;
        }
        if ($cat->category_parent === 0) {
            array_push($parent,$cat);
        } else {
            array_push($child,$cat);
        }
    }
    foreach ($parent as $key => $cat) {
        if ($key !== 0) {
            echo "-";
        }
        echo '<a href="' . get_category_link( $cat->category_parent ) .'"> ' . $cat->name . '</a>';
    }
    foreach ($child as $cat) {
        if ($key !== 0) {
            echo "-";
        }       
        echo '<a href="' . get_category_link( $cat->category_parent ) .'"> ' . $cat->name . '</a>';

    }
}
函数get\u categories\u list(){
$parent=$child=array();
foreach(获取\u类别(获取\u id())作为$cat){
如果($cat->id==0){
继续;
}
如果($cat->category_parent==0){
阵列推送($parent,$cat);
}否则{
阵列推送($child,$cat);
}
}
foreach($key=>$cat的父对象){
如果($key!==0){
回声“-”;
}
回声';
}
foreach($child作为$cat){
如果($key!==0){
回声“-”;
}       
回声';
}
}
foreach($child作为$cat){
如果($key!==0){
回声“-”;
}       
回声';
}
应该是

foreach ($child as $key => $cat) {
    if ($key !== 0) {
        echo "-";
    }       
    echo '<a href="' . get_category_link( $cat->category_parent ) .'"> ' . $cat->name . '</a>';
}
foreach($child as$key=>$cat){
如果($key!==0){
回声“-”;
}       
回声';
}

我还假设get\u category\u link($cat->category\u parent)应该是get\u category\u link($cat->ID),否则链接会非常混乱:)遗憾的是没有乐趣。这很奇怪,因为它打印了一个链接,然后就停止了
foreach ($child as $key => $cat) {
    if ($key !== 0) {
        echo "-";
    }       
    echo '<a href="' . get_category_link( $cat->category_parent ) .'"> ' . $cat->name . '</a>';
}