我有一个网站,可以从博客中获取提要。我只想提取属于两个类别(类别ID 1和类别2)的帖子。WP对此有很多文档,但是我似乎无法使其正常工作。我使用PHP文件获取供稿:
<?php
function download_page($path){
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL,$path);
curl_setopt($ch, CURLOPT_FAILONERROR,1);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION,1);
curl_setopt($ch, CURLOPT_RETURNTRANSFER,1);
curl_setopt($ch, CURLOPT_TIMEOUT, 15);
$retValue = curl_exec($ch);
curl_close($ch);
return $retValue;
}
$sXML = download_page('http://website.com/blogname/feed/atom/');
$oXML = new SimpleXMLElement($sXML);
$items = $oXML->entry;
$i = 0;
foreach($items as $item) {
$title = $item->title;
$link = $item->link;
echo '<li>';
foreach($link as $links) {
$loc = $links['href'];
$href = str_replace("/feed/atom/", "", $loc);
echo "<a href=\"$href\" target=\"_blank\">";
}
echo $title;
echo "</a>";
echo "</li>";
if(++$i == 3) break;
}
?>
$ sXML是我无法按需运行的地方。这样使用它不会更改任何“ http://website.com/blogname/feed/atom/?cat=1,2”
如何编辑URL以仅提取类别1和2中的项目?