wordpress添加天气
I was thinking about little ways to improve my blog and one small enhancement I wanted to make was adding more information to post titles when they show up in RSS feeds. Something about notifying the user via title outside of the site itself seemed like a good idea. For example, some posts are just small "quick tips", and more readers may take the time to peruse it quickly because they know it won't take too long. Here's how I accomplished that feat with WordPress.
我正在考虑改善博客的几种方法,而我想做的一个小改进就是在RSS提要中显示标题时添加更多信息。 在网站本身之外通过标题通知用户的事情似乎是个好主意。 例如,有些帖子只是一些“快速提示” ,更多的读者可能会花些时间快速阅读它,因为他们知道这不会花费太长时间。 这就是我用WordPress实现这一壮举的方式。
PHP (The PHP)
The first step is creating a function, which is provided the post title and ID, that does a category check and prepends text accordingly:
第一步是创建一个函数,为该函数提供帖子标题和ID,该函数将进行类别检查并相应地添加文本:
function show_as_tip_in_feed($title, $id) {
if(is_feed() && in_category('tips', $id)) {
$title = 'Quick Tip: '.$title;
}
return $title;
}
Once the function is there, the add_filter
hook enables the original function:
一旦函数存在, add_filter
挂钩将启用原始函数:
if(function_exists('add_filter')) {
add_filter('the_title', 'show_as_tip_in_feed', 10, 2);
}
Of course you don't need to do the category check or RSS feed check -- you can append or prepend text to any and every title, and much like other WordPress functionalities, the API easily allows developers to do so. Win!
当然,您不需要进行类别检查或RSS提要检查-您可以在任何标题中添加或添加文本,并且与其他WordPress功能一样,API可以轻松地使开发人员这样做。 赢得!
翻译自: https://davidwalsh.name/prepend-append-wordpress-titles
wordpress添加天气