2012-09-22 140 views
-2

我想從wordpress元框中的窗體中加載RSS源。我知道我在$ rss-> load字段中的代碼現在是錯誤的。我想知道如何正確檢索網址。請注意,使用PHP獲取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> 
+0

http://codex.wordpress.org/Function_Reference/fetch_feed – hakre

回答

1

嘗試取出裏面這裏的雙PHP標籤:

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

這個工作!謝謝! – user1568624

+0

優秀的,不要忘記接受答案! – endyourif