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

付费节点推荐

免费节点

节点使用教程

Clash 小火箭 v2ray节点购买

好用的梯子,海外网络,快速稳定

Google

暂时没找到相关函数实现获取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开发 #wordpress教程
评论(0)
游客的头像
表情
全部评论
最新