Home » Wordpress 技巧

控制WordPress博客文章RSS Feed的输出时间

可能你会有过这样的体验,当你刚发表一片文章的时候,却发现自己的文章中出现了某些错误。这时你可以修改你的文章,但你的错误已经随着Feed的发布而传到各个读者那里了。

这种情况经常发生在我的身上。往往我的文章中出现一些错误的时候,我的读者就会很及时地在我的博客上发表评论告诉我文章中的错误。这种情况让人难以接受,所以我决定想个方法来让文章的Feed迟一些发布,哪怕只是比文章的发布时间晚5分钟。下面就是我想出来的方法:

WordPress 是在特殊的查询( query)语句下工作的,其作用根据使用者的权限而定。通常情况下都是储存在可变量 $里面并在这里进行不同的汇编。这就意味着我们可以将它进行扩展。

如果你想通过 mySQL来实现的话,可以看看这篇文章 timestampdiff()。我是通过下面的函数(function)来实现对查询( query)的扩展的。 注意要把该扩展放在(is_feed())的前面,否则将不起任何作用。

下面的例子将使文章的 feed晚5分钟发布:

/**
 * puplish the content in the feed later
 * $where ist default-var in WordPress (wp-includes/query.php)
 * This function an a SQL-syntax
 */
function publish_later_on_feed($where) {
	global $wpdb;
 
	if ( is_feed() ) {
		// timestamp in WP-format
		$now = gmdate('Y-m-d H:i:s');
 
		// value for wait; + device
		$wait = '5'; // integer
 
		// http://dev.mysql.com/doc/refman/5.0
/en/date-and-time-functions.html#function_timestampdiff
		$device = 'MINUTE'; //MINUTE, HOUR, DAY, 
WEEK, MONTH, YEAR
 
		// add SQL-sytax to default $where
		$where .= " AND TIMESTAMPDIFF
($device, $wpdb->posts.post_date_gmt, '$now') > $wait ";
	}
	return $where;
}
 
add_filter('posts_where', 'publish_later_on_feed');

如果你把上面的语法放进主题的 functions.php 文件里面,你的博客文章的feed 就会比文章晚5分钟发布。当然,你也可以修改里面的时间。我可能该功能放进我的下一个wordpress插件©Feed里面。

原文:Publish The Feed Later | 译文:控制WordPress博客文章RSS Feed的输出时间

Popularity: 1% [?]

Share/Bookmark this!

Leave a reply

Add your comment below, or trackback from your own site. You can also subscribe to these comments via RSS.

Be nice. Keep it clean. Stay on topic. No spam.

You can use these tags:
<a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>

This is a Gravatar-enabled weblog. To get your own globally recognized avatar, please register at Gravatar.

Side Notes

This entry was posted by on May 15, 2009 at 1:29 am and filed under Wordpress 技巧 category.

You can add your comments or trackback from your own site. To keep you updated to the latest discussion, you can subscribe to these comments via RSS.

This is a Gravatar-enabled weblog. To get your own globally recognized avatar, please register at Gravatar.

最新文章

最新评论

Tag Cloud

301 Redirect 301重定向 2010 about All in one seo pack AutosCraze blog CSS Darren feed FreshMag Global Translator Google GreenFun HTML Insider name.com Problogger robots.txt文件 RSS Feed seo Wordpress Wordpress 主题 Wordpress主题 代码 优惠码 关于 博客 博客建设 域名 工具 建设 技巧 提交 插件 文章 杂志型主题 标签 注册 绿色 网赚 评论 选择 链接 页面