Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/281.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php 如何在Wordpress中显示帖子类别?_Php_Wordpress_Categories - Fatal编程技术网

Php 如何在Wordpress中显示帖子类别?

Php 如何在Wordpress中显示帖子类别?,php,wordpress,categories,Php,Wordpress,Categories,我正在WP中制作一个主题,但我找不到一种方法来显示单个帖子的类别,我想显示具有单个帖子的类别,而不是所有类别,我使用 <?php $args = array ('hide_empty' => 0,'title_li' => false,'style' => 'none',);wp_list_categories($args);?> 但这是显示所有类别,我不需要这个。我是新手,如果有人能帮我,我会很高兴的:D 在我忘记之前,如果我的英语不好,请原谅。您可以使用下

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

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

但这是显示所有类别,我不需要这个。我是新手,如果有人能帮我,我会很高兴的:D


在我忘记之前,如果我的英语不好,请原谅。

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

$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;    
}
$terms=wp\u get\u post\u terms($post\u id,'category');
foreach($terms作为$term){
echo$cat_name=$term->name;
回声“
”; echo$cat\u id=$term->term\u id; }
如果有人需要它,是

谢谢你的回答。我使用它,但没有显示任何东西我发现如何做,这么简单,是新的XD的缺点。无论如何,谢谢你回答我的问题,所以。。。你是否“接受”了一个无效的答案?