这里的“one per item”是指每个项目只有一个图标,而不是整个feed的图标。
我使用php从数据库中生成我的feed。在火狐浏览器上没有显示任何内容,但如果我在谷歌浏览器中打开URL,我可以看到所有的xml输出,而且对我来说看起来很好。
我不确定的一件事是如何包含图片,我使用了这个网站并实现了它所说的方法:
http://twigstechtips.blogspot.com/2010/10/add-image-to-your-rss-feed-item.html
我也看到了这篇SO问题:RSS feed: to feed images to your rss。这可能是最好的方法,我假设有一个php函数可以确定图像的文件大小?
我见过的最常见的方法也是SO上的一个问题:Images in RSS feed
我尝试验证反馈以测试为什么它在火狐浏览器上不显示,但由于它太大了,迄今为止我访问的所有网站都无法验证它。这是为什么它在Firefox上不显示的原因吗(在我截断CDATA部分并尝试添加图像之前,它确实曾经显示过)?
唯一的问题是我不确定它放在我的反馈中的哪里。请参见下面的源代码和示例输出:
源代码(除了包含等不必要的东西)
header("Content-Type: application/rss+xml; charset=utf-8");
$rssfeed = '<?xml version="1.0" encoding="UTF-8"?>' . "\n";
$rssfeed .= '<rss version="2.0">' . "\n";
$rssfeed .= '<channel>' . "\n";
$rssfeed .= '<title>RSS feed</title>' . "\n";
$rssfeed .= '<link>http://www.website.co.uk</link>' . "\n";
$rssfeed .= '<description>RSS feed from www.website.co.uk</description>' . "\n";
$rssfeed .= '<language>en-uk</language>' . "\n";
$rssfeed .= '<copyright>Copyright (C) 2011 website.co.uk</copyright>' . "\n\n";
$query = 'SELECT *
FROM uk_newsreach_article t1
INNER JOIN uk_newsreach_article_photo t2
ON t1.id = t2.newsArticleID
INNER JOIN uk_newsreach_photo t3
ON t2.newsPhotoID = t3.id
ORDER BY t1.publishDate DESC;';
$result = mysql_query($query) or die ("Could not execute query");
while($row = mysql_fetch_array($result)) {
extract($row);
$rssfeed .= '<item>' . "\n\t";
$rssfeed .= '<title>' . $row['headline'] . '</title>' . "\n\t";
$link= 'http://www.website.co.uk';
$url = ' . $link . '/' . $row['newsArticleID'];
$rssfeed .= '<link>' . $url . '</link>' . "\n\t";
$rssfeed .= '<guid>' . $url . '</guid>' . "\n\t";
$text = $row['text'];
$rssfeed .= '<description><![CDATA[' . $text . ']]></description>' . "\n\t";
// $rssfeed .= '<description>' . htmlentities($text) . '</description>' . "\n\t";
// add image
$rssfeed .= '<media:thumbnail url="' . $row['mediumURL'] . '" height="' . $row['mediumHeight'] . '" width="' . $row['mediumWidth'] . '" />'. "\n\t";
$rssfeed .= '<pubDate>' . date("D, d M Y H:i:s O", strtotime($row['publishDate'])) . '</pubDate>' . "\n";
$rssfeed .= '</item>' . "\n\n";
}
$rssfeed .= '</channel>' . "\n";
$rssfeed .= '</rss>' . "\n";
echo $rssfeed;
例子输出
<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0">
<channel>
<title>RSS feed</title>
<link>http://www.website.co.uk</link>
<description>RSS feed from www.website.co.uk</description>
<language>en-uk</language>
<copyright>Copyright (C) 2011 website.co.uk</copyright>
<item>
<title>Some Title</title>
<link>http://www.website.co.uk/news/articles/slug</link>
<guid>http://www.website.co.uk/news/articles/slug</guid>
<description><![CDATA[<p>Text</p>
<p>More text</p>
<p>Posted by Firstname Lastname</p>]]></description>
<media:thumbnail url="http://www.website.co.uk/img/image.jpg" height="300" width="203" />
<pubDate>Mon, 03 Oct 2011 16:57:09 +0000</pubDate>
</item>
....
....
</channel>
</rss>
<rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:media="http://search.yahoo.com/mrss/" version="2.0">
那一行。但在Firefox中仍然没有显示:( - martincarlin87