我正在尝试从 wordpress 元框中的表单加载 rss 提要 url。我知道我在 $rss->load 字段中的代码现在是错误的。我想知道如何正确检索网址。作为说明,
<?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(' & ', ' & ', $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>