我需要在我的文章(single.php)中分类的数组术语。我与wordpress中的分类术语列表
<?php $term_list = wp_get_post_terms($post->ID, 'agencia', array("fields" => "names")); print_r($term_list); ?>
试图但是html的的是:
Array ([0] => Agencia 1)
我想只显示 “1通讯社”,如果有2个方面,必须显示 “1通讯社,通讯社2”
我做错了什么?
创建分类:
//注册自定义分类 功能custom_taxonomy(){
$labels = array(
'name' => _x('Agencias', 'Taxonomy General Name', 'text_domain'),
'singular_name' => _x('Agencia', 'Taxonomy Singular Name', 'text_domain'),
'menu_name' => __('Genre', 'text_domain'),
'all_items' => __('All Genres', 'text_domain'),
'parent_item' => __('Parent Genre', 'text_domain'),
'parent_item_colon' => __('Parent Genre:', 'text_domain'),
'new_item_name' => __('New Genre Name', 'text_domain'),
'add_new_item' => __('Add New Genre', 'text_domain'),
'edit_item' => __('Edit Genre', 'text_domain'),
'update_item' => __('Update Genre', 'text_domain'),
'separate_items_with_commas' => __('Separate genres with commas', 'text_domain'),
'search_items' => __('Search genres', 'text_domain'),
'add_or_remove_items' => __('Add or remove genres', 'text_domain'),
'choose_from_most_used' => __('Choose from the most used genres', 'text_domain'),
);
$args = array(
'labels' => $labels,
'hierarchical' => false,
'public' => true,
'show_ui' => true,
'show_admin_column' => true,
'show_in_nav_menus' => true,
'show_tagcloud' => true,
);
register_taxonomy('agencia', 'post', $args);
}
// Hook into the 'init' action
add_action('init', 'custom_taxonomy', 0);
感谢,但我试过和不工作。最后我找到了正确的代码。非常感谢。 – vektor
除了包装标签 - ''和''(不会有一个“逗号”类跨度更好?) - 我提到,我真的不知道你的代码与我发布的不同。您必须将其更改为'$ term-> name',因为您已经移除了'array(“fields”=>“names”)''。很奇怪。 –
Hobo