使用PHP获取RSS源URL?

时间:2012-09-22 18:16:57

标签: php wordpress rss metadata echo

我正在尝试从wordpress元框中的表单加载rss feed url。我知道我在$ rss->加载字段中的代码现在是错误的。我想知道如何正确检索网址。作为一个说明,

<?php echo get_post_meta($post->ID, "atp_blogurl", true); ?>

用在底部的常规html中,所以我知道它是该实例中正确的php调用。

这就是我现在所拥有的:

<div id="rss_img">
<?php
$rss = new DOMDocument();
$rss->load('<?php echo get_post_meta($post->ID, "atp_blogurl", true); ?>');
$feed = array(); 
foreach ($rss->getElementsByTagName('item') as $node) {
    $item = array ( 
        'title' => $node->getElementsByTagName('title')->item(0)->nodeValue,
        'desc' => $node->getElementsByTagName('description')->item(0)->nodeValue,
        'link' => $node->getElementsByTagName('link')->item(0)->nodeValue,
        'date' => $node->getElementsByTagName('pubDate')->item(0)->nodeValue,
        );
    array_push($feed, $item);
}
$limit = 4;
for($x=0;$x<$limit;$x++) {
    $title = str_replace(' & ', ' &amp; ', $feed[$x]['title']);
    $link = $feed[$x]['link'];
    $description = $feed[$x]['desc'];
    $date = date('l F d, Y', strtotime($feed[$x]['date']));
            $description = preg_replace("/<img[^>]+\>/i", " ", $description);
    echo '<strong><a href="'.$link.'" title="'.$title.'" target="_blank">'.$title.'</a></strong><br />';
    echo '<small><em>Posted on '.$date.'</em></small><br />';
    echo '"'.$description.'<br/><br />';
}
?>
<br>
<a href="<?php echo get_post_meta($post->ID, "atp_blogurl", true); ?>"    target="_blank">View All</a>
</div>

1 个答案:

答案 0 :(得分:1)

尝试删除此处的双重php标记:

$rss->load(get_post_meta($post->ID, "atp_blogurl", true));