问题描述
我再次卡住:)
在特定Blog类别中进行搜索查询后(重定向到WP BLOG主页面),我的搜索网址看起来像
After a search query in a specific Blog Category (with redirect to the main WP BLOG page) my search url looks like
.../online-shop/?s=&category=new-posts-category&post_type=post
不幸的是,我无法在搜索结果页面中回显类别名称(new-posts-category).我想我尝试了在Wordpress Codex上找到的所有可能方法(例如 Codex -到目前为止,我的woocommerce搜索结果页面中的wich都可以正常运行.知道如何解决这个问题吗?
Unfortunately, i'm not able to echo the category Name (new-posts-category) in the search Results page. I guess i tried all possible ways i found on the Wordpress Codex (like Codex - wich works fine by the way in my woocommerce search results) page so far. Any idea how to solve this issue?
到目前为止我最接近的是(来源)
The closest i came so far is (Source)
$categories = get_the_category();
// if ( ! empty( $categories ) ) {
echo esc_html( $categories[0]->name );
// }
但是,这呼应$ categories的第一个数组元素([0])的名称.而且我不知道如何更改它,因此它会回显当前的类别名称-顺便说一下,这是唯一输出任何结果的版本.
But this one echoes the name of the first array element ([0]) of $categories. And i have no idea how to change this so it echos the current category name - it is by the way the only version wich outputs any result.
推荐答案
在发布循环中尝试以下操作:
Try this within the post loop:
$postcat = get_the_category_list( '|','',$post->ID );
echo $postcat;
这篇关于从Wordpress搜索结果页面获取类别名称的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!