如何打印Wordpress帖子的类别没有任何标记,只是纯文本?

use*_*267 4 html php wordpress

我正在创建一个wordpress主题,我在主题中的每个类别都有一个指定的颜色.我希望wordpress代码简单地将类别的名称打印到帖子的id中,这样它就可以设置为相应的颜色,但是我尝试的每个代码都会给它带来html标记,这会弄乱我的代码.以下是我希望如何工作的方式.

<article> <!-- POST -->

<h1>Post title</h1>

<h2 id="***Here is where I want to insert the code to print the post's category id***>Category Name (Same code as in the ID)</h2>

<img *featured image*>

<p>blah blah article summary</p>

</article>
Run Code Online (Sandbox Code Playgroud)

任何帮助将非常感谢!

Cha*_*e74 8

我想你想在你的代码中使用它...

 <?php foreach((get_the_category()) as $category) { echo $category->cat_name . ' '; } ?>
Run Code Online (Sandbox Code Playgroud)

假设每个帖子只有一个类别,应该可以正常工作.