这取决于你到底想做什么。但是,如果希望链接的问题具有相同的功能,可以使用相同的功能,但要将自定义分类传递给该功能。这里是您可以传递给的所有参数wp_list_categories()
和is defulat值:
<?php $args = array(
\'show_option_all\' => \'\',
//Possible values of orderby: ID, name, slug, count, term_group
\'orderby\' => \'name\',
\'order\' => \'ASC\',
\'style\' => \'list\',
\'show_count\' => 0,
\'hide_empty\' => 1,
\'use_desc_for_title\' => 1,
\'child_of\' => 0,
\'feed\' => \'\',
\'feed_type\' => \'\',
\'feed_image\' => \'\',
\'exclude\' => \'\',
\'exclude_tree\' => \'\',
\'include\' => \'\',
\'hierarchical\' => 1,
\'title_li\' => __( \'Categories\' ),
\'show_option_none\' => __(\'No categories\'),
\'number\' => null,
\'echo\' => 1,
\'depth\' => 0,
\'current_category\' => 0,
\'pad_counts\' => 0,
//Change this with your custom taxonomy
\'taxonomy\' => \'your_custom_taxonomy\',
\'walker\' => null
);
wp_list_categories($args);
?>
上面的代码将以层次顺序生成一个列表,其中包含指定分类法中的所有术语,而不仅仅是与当前帖子关联的术语。但我们可以使用
inlcude
参数:
<?php
global $post;
$taxonomy = \'your_taxonomy\';
// get the term IDs assigned to post.
$post_terms = wp_get_object_terms( $post->ID, $taxonomy, array( \'fields\' => \'ids\' ) );
if ( !empty( $post_terms ) && !is_wp_error( $post_terms ) ) {
$term_ids = implode( \',\' , $post_terms );
$args = array(
\'taxonomy\' => $taxonomy,
\'include\' => $term_ids,
//Add more arguments if you need them with a different value from default
);
$terms = wp_list_categories($args);
// display post categories
echo $terms;
}
?>