WordPress:Customizing Feeds

来自站长百科
Seadragon530讨论 | 贡献2008年4月19日 (六) 17:35的版本
跳转至: 导航、​ 搜索

If terms like feed, syndication, and RSS make your head spin, stop right now and read an Introduction to Syndication. That will give you a good overview of feeds and syndication. We have an article on WordPress:WordPress Feeds to help you understand the basics, if you need them, but from here on, this article assumes that you know the basics of what feeds are and how they are used.

如果象feedsyndication, 和 RSS这些词语让你头脑发晕,现在就停下来读读Syndication介绍。这会给你一个 feed总览,包括syndication。如果你需要的话,我们有一个关于WordPress Feeds的文章,帮助你理解基础,从这里开始,本文假设你懂得feed是什么和如何使用它们。

Customized feeds give your readers more information about you and your blog: you can include the names of additional collaborators on your blog posts, or a link to your Friend-of-a-Friend file. Contrariwise, it can also help you restrict the information available for syndication, by removing extraneous data or providing a machine-readable version of your copyright statement.

制定feed,给你的读者更多关于你和你的blog的信息:你可以把附加的合作伙伴的名字放到你的blog文章上,或者连接到朋友的朋友。反之,它同样也可以帮助你限制syndication可以获得的信息,通过移除外来数据或者提供机器可读的你的版权声明。

How WordPress Produces Feeds

WordPress uses a set of feed templates to display your site's feeds, in much the same way as it uses theme templates to display your content. These feed templates are located in the main WordPress directory; they are not compatible with the Theme system.

WordPress如何生成Feeds

WordPress使用了feed的模板集合来显示你的页面feed,多数情况下和使用主题模板显示内容相同。这些feed模板再WordPress主目录中,它们和主题系统并不一致。

The following feed templates are included with WordPress:

wp-rss2.php
Displays your entries in RSS 2.0 format.
wp-rss.php
Displays your entries in RSS 0.92 format.
wp-rdf.php
Displays your entries in RDF/RSS 1.0 format
wp-atom.php
Displays your entries in Atom format.
wp-commentsrss2.php
Displays comments - either the most recent comments on all posts, or the comments on a specific post - in RSS 2.0 format.

WordPress包含下边的feed模板:

wp-rss2.php
使用RSS 2.0 格式显示你的登陆口。
wp-rss.php
使用RSS 0.92格式显示你的登陆口。
wp-rdf.php
使用RDF/RSS 1.0格式显示你的登陆口。
wp-atom.php
使用 Atom格式显示你的登陆口。
wp-commentsrss2.php
显示评论 – 可以是所有文章的最新评论也可以是某个特定文章的评论 - RSS 2.0 格式。


Customizing Your Feeds

There are a variety of ways to customize your feeds, through the use of third-party software you install and add-on to your WordPress site, or by manually changing the feed templates to meet your needs.

定制Feed

有多种方法来定制你的feed,通过你安装并用于WordPress站点的第三方软件,或者手动的更改feed模板来打到你的要求。

Third-Party Software

Some third-party web services can help you manage and customize your feeds. Using such services can be a simple way to do things like counting the number of people who read your feed, or combining your blog's feed with your Flickr photostream.

Such services include:

第三方软件

一些第三方软件网页服务可以帮助你管理和定制你的feed。使用这种服务可以说是一种方便的方法去做一些如计算阅读feed的人数,或者用Flickr photostream合并blog的feed这一类的事情。

这些服务包括:

Customizing Feed Templates

Editing your feed templates is much the same as editing your theme templates. However, feed templates are not integrated into the WordPress theme system; if you would like different versions of your feeds, you'll need to create extra feed templates or apply this patch to your WordPress installation.

制定feed模板

编辑你的feed模板很大程度上和编辑你的主题模板一样。尽管如此,feed模板并没有统一到 WordPress模板系统中;如果你想要不同的feed,你需要创建额外的feed模板或者再你的WordPress安装中应用这个补丁

Many specialized template tags exist specifically to format your content in a way that complies with the RSS standards. They include:

Let's look at some examples of how to use these template tags with your WordPress site feeds.

很多特殊存在的专门的模板标签是用来根据RSS标准格式化你的内容的 。包括:


Make PubDate Work with Wordpress 2.2

With regards to the below, wp-rss2.php no longer has the pubDate command, but /wp-includes/feed-rss2.php does on lines 20, and 22.

If you are American, I suggest replacing said lines with the below:

<pubDate><?php echo mysql2date('m-d-Y', get_post_time('Y-m-d H:i:s', true), false); ?></pubDate>

让PubDate 在Wordpress 2.2中使用

从下边的 内容可以看出,wp-rss2.php不再有pubDate命令,但是在20和22行的/wp-includes/feed-rss2.php命令中包含。

如果你是美国人,建议使用下面语句代替所说的两行:

<pubDate><?php echo mysql2date('m-d-Y', get_post_time('Y-m-d H:i:s', true), false); ?></pubDate>

Make PubDate Work with Non-English Dates

The default RSS 2.0 feed in WordPress 1.5 displays the date elements of posts using some language-specific terms, i.e., day and month names. If you're using a localized version (non-English) of WordPress, some feed readers may not correctly interpret these names, causing errors in display and/or validation. If you are using a WordPress version later than 1.5.1, the problem with international dates in feeds has been fixed.

让PubDate 可以用于非英语的日期

WordPress 1.5中,默认RSS2.0feed使用一些语言相关的条目显示文章的日期元素,如日和月的名字。如果你用地方版本(非英语)的WordPress,一些feed读取器可能不能正确的分隔这些名字,导致显示错误或者非法操作。如果你使用WordPress 1.5.1之后的版本, feed的国际时间的问题已经被修正了.

To solve this problem in prior versions of WordPress, open wp-rss2.php and change the entry pubDate element from:

<pubDate>
<?php echo mysql2date('D, d M Y H:i:s +0000', get_the_time('Y-m-d H:i:s')); ?>
</pubDate>

to:

<pubDate>
<?php echo mysql2date('r', get_the_time('Y-m-d H:i:s')); ?>
</pubDate>

为了解决老版本WordPress的这个问题,打开wp-rss2.php改变pubDate的内容,把下边内容:

<pubDate>
<?php echo mysql2date('D, d M Y H:i:s +0000', get_the_time('Y-m-d H:i:s')); ?>
</pubDate>

该成:

<pubDate>
<?php echo mysql2date('r', get_the_time('Y-m-d H:i:s')); ?>
</pubDate>

The 'r' is a generic PHP date format that does not rely on translated strings.

'r'是一类不依赖于标准字符串的PHP 日期格式

Adding Entry Titles to Your Comments Feed

This example sets the title of each item in your comments RSS feed from By: Harriet to Harriet on Sample Post, which helps provide some context when reading the main feed of all comments on your blog. Because the_title_rss doesn't work outside WordPress:The Loop, it's necessary to duplicate part of its function in your template.

给评论feed添加登陆口标题

这个例子是:在你的RSS feed中,从By: HarrietHarriet on Sample Post,设置每个项目的标题。这对阅读blog上所有评论的主feed时提供一些上下文是有帮助的。因为the_title_rss不能工作在Loop之外,它的功能在你的主题中是必须的部分

The following code should be put in wp_commentsrss2.php, just after the beginning of the comment loop:

如下代码应该放在wp_commentsrss2.php中,再评论loop开始之后的地方:

<item>
<?php
  /* First, grab the title of the entry on 
     which the comment was posted */
  $title = get_the_title($comment->comment_post_ID);

  /* Now sanitize the formatting for RSS */
  $title = apply_filters('the_title', $title);
  $title = apply_filters('the_title_rss', $title);
?>
<title><?php comment_author_rss() ?> on <?php echo $title ?></title>

Alternatively, this plugin will achieve the same result without hacking your wordpress install.

相应的,这个插件将再不破坏wordpress安装的情况下得到相同的结果。

Checking Your New Feed

To see your new feed, you can use any of the many feed readers available on the Internet. While your feed might look good to you in the different readers, it might still have problems.

检查新的Feed

要看你的新的Feed,你可以使用任何feed读取器。如果feed在哪个读取器中看起来正常的话,再别的读取器中可能会出问题。

Feed formats are designed to be read and manipulated by machines; errors in your feed template can make your feed unreadable to some or all feedreaders. So after you make all your changes, it's a good idea to check that your feed meets the relevant standards. Validation services include:

Feed格式设计成机器可以读并操作的类型;feed模板中的错误可能导致某些feed读取器无法读取你的feed。所以做完所有你要做的更改之后,检查你的feed是否达到相关标准是必须的。确认服务包括:

More Information and Resources

更多信息和资源


This article is [[WordPress::Category:Copyedits|marked]] as in need of editing. You can help Codex by editing it.