How to Feed WordPress Posts in a External Website with PHP?

I have 2 web sites, one is based on WordPress a PHP website. I intend to feed the last 10 posts from that WordPress blog to this PHP website. Taking the title, url and thumbnail, and all this from two specific post category.

An Easy Way to Display an RSS Feed with PHP code:
The following code will first create a new DOMDocument() into which we will load the RSS feed. Say I will get the posts from the category called eyeglasses of<!–more–>

$rss = new DOMDocument();

Then we will single out certain elements and place them into an array. For this example, I will just fetch the title, description, link and published on date.

$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);

Finally, we set it to display 10 posts on screen with the titles linking directly to the original post.
$limit = 10;
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’]));
echo ‘<p><strong><a href=”‘.$link.'” title=”‘.$title.'”>’.$title.'</a></strong><br />’;
echo ‘<small><em>Posted on ‘.$date.'</em></small></p>’;
echo ‘<p>’.$description.'</p>’;

Not too complicated. All you need to change is the feed you want to load (line #3) and the number of posts to display (line #14). Of course, you could always play around with the output to get it styled exactly how you want. That is totally up to you.