问题
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