How to show post categories in Wordpress?

依然范特西╮ 提交于 2021-02-11 09:59:13

问题


i'm making a theme in WP but i can't find a way to show the categories of a single post, i want to display the categories that have a single post not all categories, i was using...

<?php $args = array ('hide_empty' => 0,'title_li' => false,'style' => 'none',);wp_list_categories($args);?>

But this is showing all categories and i don't need this. I'm new in this and i'm gonna be happy if somebody can help me :D

Before i forget, sorry if my english is bad.


回答1:


You can get all categories for particular post using below code

$terms = wp_get_post_terms($post_id,'category');
foreach ($terms as $term) {
    echo $cat_name = $term->name;
    echo "<br>";
    echo $cat_id = $term->term_id;    
}



回答2:


If somebody need it, is <?php the_category(',');?>



来源:https://stackoverflow.com/questions/25819634/how-to-show-post-categories-in-wordpress

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!