Read Wordpress RSS Feeds, YouTube Video Lists, and more…

I needed to grab a couple of new blog entries on a website’s wordpress blog area, and put it on a non-wordpress home page. I ended up making a PHP 5 class that did the job for me. Very simple, no fancy stuff.

I then needed to get a load of youtube video posts on the same site from a specific account and had to make a list of that, with thumbnails etc. . I ended up tweaking the first class ever so slightly and lucky me, I had an easy feed reader.

This class has some limitations, this is because it does what I need it to do:

  • You only get the items specified. In the case of wordpress RSS, you’d only get all the <item></item> elements for easy reading.
  • Only first child values are used. If an element within the elements you searched for has children, you won’t have easy reading of their values.
  • Attributes are not available for easy reading.

There is a simple workaround for these limitations, which is by using the DOMDocument object stored in the ReadFeed object. You can access it via $ReadFeedObj->dom->etc…

This class needs php 5 and will not work with earlier versions

I have added some documentation which you can find here, along with the source code.

Here is a simple example for getting your wordpress posts:

$feed = new ReadFeed("http://www.netweblogic.com/feed", "item");
foreach ($feed-&gt;items as $item){
?>
<div>
  <h3>title</h3>
  <?= $item->description ?>
  <a href="<?= $item->link ?>">more</a>
</div>
<?
}

So there you have it. Quick explanation:

First line creates the object, using my website as an example and in the case of RSS each post is in the <item> tag. Then we iterate through each item in the items array property, and get the values within each <item> by simply using $item->tagName.

Tags: , , , , ,

One Response to “Read Wordpress RSS Feeds, YouTube Video Lists, and more…”

  1. download youtube video Says:

    nice article thanks for information.im trying this system on php5,i can write my result on this page.

    thanks for all.

Leave a Reply