当前位置:K88软件开发文章中心编程全书编程全书02 → 文章内容

wordpress获取自定义文章类型post_type的分类列表

减小字体 增大字体 作者:佚名  来源:网上搜集  发布时间:2019-1-4 9:20:50

-->

暂时没找到相关函数实现获取post_type分类列表,当然不怕麻烦可以做个菜单单独存放,还是没问题的。试过了?wp_list_cats(),the_category() 都无效。

/**

* 获取当前自定义类型的,分类名称!

* @return string

*/

function custom_taxonomies_terms_links(){

//根据当前文章ID获取文章信息

$post = get_post( $post->ID );

//获取当前文章的文章类型

$post_type = $post->post_type;

//获取文章所在的自定义分类法

$taxonomies = get_object_taxonomies( $post_type, ‘objects’ );

$out = array();

foreach ( $taxonomies as $taxonomy_slug => $taxonomy ){

$term_list = wp_get_post_terms($post->ID, $taxonomy_slug, array(“fields” => “all”));

echo $term_list[0]->name; //显示文章所处的分类中的第一个

}

return implode(”, $out );

}


wordpress获取自定义文章类型post_type的分类列表