我使用以下php代码从我的wordpress网站加载rss feed到另一个,但它没有得到实际帖子的链接这对我来说是一个问题我似乎无法修复它
<?php
$feed = simplexml_load_file('http://www.example.com/rss.xml');
foreach ($feed->channel->item as $item) {
$title = (string) $item->title;
$description = (string) $item->description;
print '<div class="entry">';
printf(
'<h2>%s</h2><p>%s</p>',
$title,
$description
);
if ($media = $item->children('media', TRUE)) {
if ($media->content->thumbnail) {
$attributes = $media->content->thumbnail->attributes();
$imgsrc = (string)$attributes['url'];
printf('<div><img src="%s" alt="" /></div>', $imgsrc);
}
}
echo '</div>';
}
?>
答案 0 :(得分:1)
在阅读了有关RSS Feed的XML结构之后,我能够编辑上面的代码,从而提供了一个简单的RSS embeder:)
<?php
$feed = simplexml_load_file('http://presstv.bg/?feed=rss');
foreach ($feed->channel->item as $item) {
$link = (string) $item->link;
$title = (string) $item->title;
$description = (string) $item->description;
print '<div class="entry">';
printf(
'<a href="%s"><h2>%s</h2></a><p>%s</p>',
$link,
$title,
$description
);
if ($media = $item->children('media', TRUE)) {
if ($media->content->thumbnail) {
$attributes = $media->content->thumbnail->attributes();
$imgsrc = (string)$attributes['url'];
printf('<div><img src="%s" alt="" /></div>', $imgsrc);
}
}
echo '<div class="clear"></div>';
echo '</div>';
}
?>