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

付费节点推荐


免费节点


节点使用教程


暂时没找到相关函数实现获取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 );

}

未经允许不得转载:Bcoder资源网 » wordpress获取自定义文章类型post_type的分类列表

相关推荐

更多优质资源关注微信公众号: bcoder

bcoder
赞 (1)
分享到:更多 ()

评论 0

评论前必须登录!

登陆 注册