最新下载
热门教程
- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
- 9
- 10
wordpress获取自定义post_type的分类例子
时间:2022-06-25 18:51:48 编辑:袖梨 来源:一聚教程网
在自己建立一种post-type的文件类型后,然后分类也是自己用register_taxonomy来自定义的。
这个时候我在用
| 代码如下 | 复制代码 |
| [php][/php] | |
来获取当前文章的分类,取到的数据是空。
百度后用 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] | |
相关文章
- 燕云十六声听梅点雪怎么打 听梅点雪打法攻略 11-17
- 境界刀鸣黑崎一护刻印怎么选 黑崎一护刻印选择推荐 11-17
- 境界刀鸣浦原喜助技能是什么 浦原喜助技能详解 11-17
- 境界刀鸣石田雨龙技能是什么 石田雨龙技能详解 11-17
- 洛克王国世界极品宠物蛋怎么获取 极品宠物蛋获取攻略 11-17
- 明日方舟终末地能力值是什么 能力值介绍一览 11-17