[英]wordpress if post is in_category display category name
I want to check if a Wordpress post has category 'X, Y or Z' and if so display the name(s) of the category ('XY or Z').我想检查 Wordpress 帖子是否具有类别“X、Y 或 Z”,如果是,则显示类别名称(“XY 或 Z”)。
I already check and get a true of the category, but how can I show each name that has been found in_category();我已经检查并获得了类别的真实性,但是如何显示在_category() 中找到的每个名称;
if ( in_category( array( 'X', 'Y', 'Z') {
echo "yes";
}
How can I display the category name?如何显示类别名称?
the simple answer to your question is this你的问题的简单答案是这样的
get_the_category();
Using your example you can say使用您的示例,您可以说
if (in_category( array('X', 'Y', 'Z') )) {
echo get_the_category();
}
This tag may be used outside The Loop by passing a post ID as the parameter.
通过将帖子 ID 作为参数传递,此标签可以在 The Loop 之外使用。
For more information and usage of get_the_category()
visit the next link有关
get_the_category()
的更多信息和用法,请访问下一个链接
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.