如何在WordPress中发布帖子中的类别标题?
问题描述:
假设我在Wordpress中有一个名为Hello World的帖子,我直接查看该页面,我将如何去查找“Hello World”类别并显示它?如何在WordPress中发布帖子中的类别标题?
答
使用get_the_category()
这样的:
<?php
foreach((get_the_category()) as $category) {
echo $category->cat_name . ' ';
}
?>
它返回一个列表,因为一个帖子可以有多个类别。
The documentation也解释了如何从循环之外做到这一点。
答
您可以使用
<?php the_category(', '); ?>
这将输出他们在一个逗号分隔的列表。
你也可以做标记相同的还有:
<?php the_tags('<em>:</em>', ', ', ''); ?>