wordpress:将类别添加到帖子 RSS 标题
我希望 RSS 条目标题如下所示:
“这是帖子标题 [category1,category4]”
方括号中列出了帖子提交的类别。
我首先修改了 wp-feed.php 文件,但它很脏:每次 WordPress 更新都会删除我的更改。所以我想我可以通过 add_filter 来做到这一点。我这样设置,但我不知道如何访问我的函数中的帖子类别。有什么想法吗?
function rssTitle_add_categories($title) {
// how do i retrieve the category array ?
$categories = join(', ', $category_array);
$title = $title . '['.$categories.']';
return $title;
}
add_filter('the_title_rss', 'rssTitle_add_categories');
I would like that the RSS entries titles be like this:
"this is the post title [category1, category4]"
In square brackets are listed the categories in which the post is filed.
I first modified the wp-feed.php file, but it's dirty: every wordpress update will erase my changes. So i think i can do this via add_filter. I set it up like this, but i don't know how i can have access to the post categories within my function. Any idea?
function rssTitle_add_categories($title) {
// how do i retrieve the category array ?
$categories = join(', ', $category_array);
$title = $title . '['.$categories.']';
return $title;
}
add_filter('the_title_rss', 'rssTitle_add_categories');
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
当(从提要模板)调用
the_title_rss
过滤器函数时,您处于 WordPress 帖子循环内,因此通常的函数应该可以工作。你应该能够做这样的事情:When
the_title_rss
filter functions are called (from the feed templates) you are inside a Wordpress posts loop, and so the usual functions should work. You should be able to do something like this: