Display RSS Feed Content with SimplePie

Here, we have write article about the display RSS feed content with simplePie.

Adding content from a RSS feed on website can be quite a task, thankfully the SimplePie library has helped add the Really Simple back into Really Simple Syndication. In this article we will cover how to add the 5 latest headlines from a RSS feed that link back to the articles from the original website.

Download the SimplePie Library Firstly you will need to download the SimplePie library. Unzip the file and copy simplepie.inc to the root directory of your web server, in this example I am going to add it to the following directory /inc

Reference SimplePie and the RSS Feed at the top of each page. Once you have uploaded the SimplePie library to the server, you will need to reference it at the top of each page the RSS content is going to be displayed on using the following piece of code:

Once the SimplePie library has been loaded you will need to include the location of the RSS Feed or Atom Feed you are wanting to pull the information from by adding the following variable to the block of code above (make sure you replace the example URL with the address of the feed you are wanting to pull the information from).

So altogether the block of PHP at the top of each of page should look like this:

Retrieving the Content Now let’s get the RSS content. To do this, we will retrieve an array of posts from the SimplePie object and phrase them into a unodered list using the following code:

That’s everything! You should now have a list of the latest headlines from a RSS feed, linked to the articles from the original website.