根据需要使用此函数列出所有分类术语和链接
function get_term_list($taxonomy){
$terms = get_terms($taxonomy);
echo \'<ul class="list-cat">\';
foreach ( $terms as $term ) {
// The $term is an object, so we don\'t need to specify the $taxonomy.
$term_link = get_term_link( $term );
// If there was an error, continue to the next term.
if ( is_wp_error( $term_link ) ) {
continue;
}
// We successfully got a link. Print it out.
echo \'<li><a href="\' . esc_url( $term_link ) . \'">\' . $term->name . \'</a></li>\';
}
echo \'</ul>\';
}
并包括(&A);在管理面板中为您的页面使用此短代码
[all\\u get\\u term\\u list分类法=“category”]
默认情况下,这个短码使用的分类法是category
add_shortcode ( \'all_get_term_list\', \'all_get_term_list\' );
function all_get_term_list($atts){
$a = shortcode_atts( array(
\'taxonomy\' => \'category\'
), $atts );
$terms = get_terms($a[\'taxonomy\']);
$output.= \'<ul class="list-cat">\';
foreach ( $terms as $term ) {
// The $term is an object, so we don\'t need to specify the $taxonomy.
$term_link = get_term_link( $term );
// If there was an error, continue to the next term.
if ( is_wp_error( $term_link ) ) {
continue;
}
// We successfully got a link. Print it out.
$output.= \'<li><a href="\' . esc_url( $term_link ) . \'">\' . $term->name . \'</a></li>\';
}
$output.= \'</ul>\';
return $output;
}