如何在Wordpress中显示帖子类别? [英] How to show post categories in Wordpress?

查看:59
本文介绍了如何在Wordpress中显示帖子类别?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在WP中制作主题,但是我找不到一种方法来显示单个帖子的类别,我想显示一个帖子而不是所有类别的类别,我正在使用...

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);?>

但是这显示了所有类别,我不需要这个.我是新来的,如果有人可以帮助我,我会很高兴:D

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.

推荐答案

您可以使用以下代码获取特定帖子的所有类别

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;    
}

这篇关于如何在Wordpress中显示帖子类别?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆