這是個簡單的方法,在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>';
}