Incorporating an RSS feed into HTML page?

Soldato
Joined
20 Nov 2002
Posts
11,141
Location
Barnsley
Hi,

Basically I have created a website layout using HTML and CSS.

On one of these pages I aim to incorporate the text from an existing RSS feed (created by Word Press), whilst keeping it in the same style and format as the other pages (keeping it all in the content div basically).

So in short I want the HTML to exist as my front end and just log into Word Press (in a different directory/url) when I want to update the "news" page of my site.

I was wondering if there was a piece of code that would enable me to do this or if there are any other simple alternatives?

Cheers for any help :)
 
The simplest (but perhaps not the most elegant) way would be to use one of the many RSS to JavaScript services. That's simply a case of pointing the URL at the webservice.

The best way to do it would be to use a server side language to parse, cache and display the RSS content. Assuming you've got a Linux server with PHP installed, you could try something like Magpie or SimplePie, both of which are really effective and quite simple to set up.

Or, you could write it yourself in PHP. It's relatively simple to do this in PHP5, thanks to the incorporation of the SimpleXML functions.
 
Here's a very basic PHP-based RSS parser. As there are several different formats of RSS, and each feed can contain slightly different tags, you may need to modify it. If you uncomment the print_r statement, you'll see the associative array, so you can add extra bits if need be.

<?php
$url = "http://www.practicalfishkeeping.co.uk/pfk/xml/fishnews.rss";
$xml = new SimpleXmlElement(file_get_contents($url));

/*
echo "<pre>";
print_r($xml);
echo "</pre>";
*/

echo "<ul>";
foreach($xml->channel->item as $item){

$article = array();
$article['title'] = $item->title;
$article['link'] = $item->link;

echo "<li><a href=\"".$article['link'].">".$article['title']."</a></li>\n";

}

echo "</ul>";

?>
 
Back
Top Bottom