I use a snippet loosely based on one from the coding pad :
<?php
function url_exists($url) {
// Version 4.x supported
$handle = curl_init($url);
if (false === $handle)
{
return false;
}
curl_setopt($handle, CURLOPT_HEADER, false);
curl_setopt($handle, CURLOPT_CONNECTTIMEOUT, 1);
curl_setopt($handle, CURLOPT_TIMEOUT, 5);
curl_setopt($handle, CURLOPT_FAILONERROR, true); // this works
curl_setopt($handle, CURLOPT_HTTPHEADER, Array("User-Agent: Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.8.1.15) Gecko/20080623 Firefox/2.0.0.15") ); // request as if Firefox
curl_setopt($handle, CURLOPT_NOBODY, true);
curl_setopt($handle, CURLOPT_RETURNTRANSFER, false);
$connectable = curl_exec($handle);
curl_close($handle);
return $connectable;
}
$i=0;
$feed_url = 'http://www.your-wp-domain.com/blog/feed/';
if (url_exists($feed_url)) {
$xml = simplexml_load_file($feed_url);
$o .='<div class="greybox-clear"></div>
<div class="greybox">
<h4>Blog Headlines</h4>';
foreach($xml->channel->item as $key => $value)
{
if ($i < '1')
{
$stamp = explode(" ", $value->pubDate);
$o .= '<p>
<b><a href="'.$value->link.'" title="'.$value->title.'">'.$value->title.'</a></b><br />
<i>'.$stamp[0].' '.$stamp[1].' '.$stamp[2].' '.$stamp[3].' </i><br />
'.substr($value->description,0,100).'...
</p>';
}
$i++;
}
$o .= '</div><!-- close greybox --><div class="greybox-clear"></div>';
}
else {
$o .= '';
}
return $o;
?>
Sorry, the html is mixed up in there, but you get the idea.
Don’t forget to change the
$feed_url value.