【www.bbyears.com--WordPress】
在自己建立一种post-type的文件类型后,然后分类也是自己用register_taxonomy来自定义的。
这个时候我在用
来获取当前文章的分类,取到的数据是空。
百度后用 query_posts 指定post-type.获取还是不ok。
最后只能通过添加个function来获取。
代码如下[php]
/**
* 获取当前自定义类型的,分类名称!
* @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 );
}
[/php]