这是个简单的方法,在WordPress中列出一篇文章的所属类别名称。通过以下这段代码就可以实现。

$postId = 1;
//note: if you code in single.php, do not need to pass the id
$categories = get_the_category($postId);

//iterate categories and print $category->cat_name
foreach($categories as $category){
    echo '<a href="' . get_category_link($category) . '">' . $category->cat_name . '</a>';
}