从帖子ID获取类别名称 [英] Get Category name from Post ID
本文介绍了从帖子ID获取类别名称的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
是否可以使用给定的帖子ID获取类别的类别名称,以下代码可以获取类别ID,但是如何获取名称?
Is it possible to get the category name of a category given the Post ID, the following code works to get the Category Id, but how can I get the name?
<?php $post_categories = wp_get_post_categories( 4 ); echo $post_categories[0]?>
谢谢!
推荐答案
此处为 get_the_category($ post-> ID);
将返回您需要遍历数组的帖子的类别数组
here you go get_the_category( $post->ID );
will return the array of categories of that post you need to loop through the array
$category_detail=get_the_category('4');//$post->ID
foreach($category_detail as $cd){
echo $cd->cat_name;
}
这篇关于从帖子ID获取类别名称的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文