专为导航而生,在wordpress模板制作过程中常常会在做breadcrumbs导航时会用到,子分类调用父分类的名称和链接,下面这段简洁的代码,可以完美解决这个问题。


下面这种方法也可以,不过代码不够简洁。

term_id;

echo get_term_parents_list( $term_id, ‘category’ );
}
?>
第三种方法,调用分类目录名称和链接,作为导航。

$query_obj = get_queried_object();
$term_id = $query_obj->term_id;
$taxonomy = get_taxonomy( $query_obj->taxonomy );

if ( $term_id && $taxonomy ) {
// Add taxonomy label name to the trail.
// $trail .= ‘/’ . $taxonomy->labels->menu_name;
// Add term parents to the trail.
$trail .= ‘/’ . get_term_parents_list( $term_id, $taxonomy->name, array( ‘inclusive’ => false ) );
}

// Print trail and add current term name at the end.
echo ‘

‘;
}
?>

声明:本站所有文章,如无特殊说明或标注,均为本站原创发布。任何个人或组织,在未征得本站同意时,禁止复制、盗用、采集、发布本站内容到任何网站、书籍等各类媒体平台。如若本站内容侵犯了原著者的合法权益,可联系我们进行处理。