以下示例插件可让您访问自定义提要 url 并输出自定义 rss 内容。在这种情况下,URL 是 *http:///?feed=custom_user_feed*。问题在于它的格式不正确,谷歌浏览器无法将其识别为提要。IE 和 Firefox 则相反。
/* Plugin Name: Sample Custom User Feed */
add_action('init', array(new custom_user_feed, "add_feed"));
class custom_user_feed {
protected $feed_query = 'custom_user_feed';
protected $title = 'custom user feed sample';
protected $link = 'http://www.stackoverflow.com';
protected $urls = array(
"http://stackoverflow.com/feeds"
);
protected $description = 'this is a sample to demonstrate a custom user feed.';
protected $language = 'en-us';
protected $itemlimit = 5;
function add_feed() {
add_feed($this->feed_query, array(&$this, "output_rss"));
}
function output_rss() {
$feed = fetch_feed($this->urls);
$feed->set_item_limit($this->itemlimit);
echo '<?xml version="1.0" encoding="UTF-8" ?>';
?>
<rss version="2.0">
<channel>
<title><?php echo $this->title; ?></title>
<link><?php echo $this->link; ?></link>
<description><?php echo $this->description; ?></description>
<language><?php echo $this->language; ?></language>
<?php
foreach($feed->get_items() as $item) {
?>
<item>
<title><?php echo $item->get_title(); ?></title>
<link><?php echo $item->get_permalink(); ?></link>
<description>
<?php echo $item->get_description(); ?>
</description>
</item>
<?php
}
?>
</channel>
</rss>
<?php
}
}
有人能在格式中找到错误吗?谢谢。