我在wordpress的functions.php中设置了分类法(我在自定义帖子类型中制作):
add_action( 'init', 'create_post_type' );
function create_post_type() {
register_post_type( 'clip',
array(
'labels' => array(
'name' => __( 'Clips' ),
'singular_name' => __( 'Clip' )
),
'public' => true,
'has_archive' => true,
'hierarchical' => true,
'supports' => array('editor', 'excerpt', 'thumbnail', 'title')
)
);
// Add new taxonomy, NOT hierarchical (like tags)
$labels = array(
'name' => _x( 'Directors', 'taxonomy general name' ),
'singular_name' => _x( 'Director', 'taxonomy singular name' ),
'search_items' => __( 'Search Directors' ),
'popular_items' => __( 'Popular Directors' ),
'all_items' => __( 'All Directors' ),
'parent_item' => null,
'parent_item_colon' => null,
'edit_item' => __( 'Edit Director' ),
'update_item' => __( 'Update Director' ),
'add_new_item' => __( 'Add New Director' ),
'new_item_name' => __( 'New Director Name' ),
'separate_items_with_commas' => __( 'Separate Directors with commas' ),
'add_or_remove_items' => __( 'Add or remove Directors' ),
'choose_from_most_used' => __( 'Choose from the most used Directors' ),
'menu_name' => __( 'Directors' ),
);
register_taxonomy('director','clip',array(
'hierarchical' => false,
'labels' => $labels,
'show_ui' => true,
'update_count_callback' => '_update_post_term_count',
'query_var' => true,
'rewrite' => array( 'slug' => 'director' ),
));
} //end clip creation PT
现在我想把它叫出去,但似乎不能。
这是我正在使用但不起作用的方法。
echo get_the_term_list( $post->ID, 'director', 'director: ', ', ', '' );
你知道如何解决这个问题吗?
答案 0 :(得分:0)
$args=array(
'name' => 'director'
);
$output = 'objects';
$taxonomies=get_taxonomies($args,$output);
if ($taxonomies) {
foreach ($taxonomies as $taxonomy ) {
echo '<p>' . $taxonomy->name . '</p>';
}
}