如何在Wordpress中的文章中获取类别标题? [英] How to get the category title in a post in Wordpress?

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

问题描述

假设我在Wordpress中有一个名为Hello World的文章,我直接查看这个页面,我将如何去查找Hello World类别并显示它?

解决方案

使用 get_the_category() 像这样:

 <?php 
foreach((get_the_category ))作为$ category){
echo $ category-> cat_name。 '';
}
?>

它返回一个列表,因为一个帖子可以有多个类别。



文档还解释了如何在循环之外执行此操作。

Say I have a post called Hello World in Wordpress and I'm directly viewing this page, how would I go about finding the category of "Hello World" and displaying it?

解决方案

Use get_the_category() like this:

<?php
foreach((get_the_category()) as $category) { 
    echo $category->cat_name . ' '; 
} 
?>

It returns a list because a post can have more than one category.

The documentation also explains how to do this from outside the loop.

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

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