Hello,
我有一个带有8个分类法的“自定义帖子类型”,我假装显示一个只有6个分类法的列表,并且不清空每个分类法的术语,隐藏2个分类法。我当前的代码显示了所有分类法,所有术语都隐藏了空的分类法,但我无法获得如何隐藏我想要的两个分类法。
这是我的代码:
<? php
$args = array(
\'public\' => true,
\'_builtin\' => false
);
// $output = \'names\'; // or objects
// $operator = \'and\'; // \'and\' or \'or\'
// $taxonomies = get_taxonomies( $args, $output, $operator );
$object = \'my-cpt-name\';
$output = \'names\';
$taxonomies = get_object_taxonomies( $object, $output );
if ( $taxonomies ) {
foreach ( $taxonomies as $taxonomy ) {
echo \'<h3>\' . $taxonomy . \'</h3>\';
$args = array( \'hide_empty=0\' );
$terms = get_terms( $taxonomy, $args );
if ( ! empty( $terms ) && ! is_wp_error( $terms ) ) {
$count = count( $terms );
$i = 0;
$term_list = \'<ul class="term-list">\';
foreach ( $terms as $term ) {
$i++;
$term_list .= \'<li><a href="\' . esc_url( get_term_link( $term ) ) . \'" >\' . $term->name . \'</a></li>\';
if ( $count != $i ) {
}
else {
$term_list .= \'</ul>\';
}
}
echo $term_list;
}
}
}
?>
我已将“public”分类法$arg设置为“false”,但不起作用。$args = array(
\'labels\' => $labels,
\'hierarchical\' => true,
\'public\' => false,
\'show_ui\' => true,
\'show_admin_column\' => true,
\'show_in_nav_menus\' => true,
\'show_tagcloud\' => true,
);
还有,如何显示分类名称而不是echo \'<h3>\' . $taxonomy . \'</h3>\';