NOTE: PHP5 Only

Authors

Summary

This script allows you to easily display items from an RSS feed, this’d be great for showing @commented-on, del.icio.us, Technorati or even your companies feed.

Although the format of this script is Wordpress plugin orientated, it doesn’t need Wordpress and can be used as a general function. Unfortunately, this is PHP5 only as it takes advantage of PHP5’s DOM functions.

NOTE: It can be used as many times as you like (you can call getFeed as many times as you like) but this version does NOT have caching yet, so if your calling someone else’s feed, be gentle.

File


/*
Plugin Name: getRSS
Plugin URI: http://www.zachinglis.com/projects/getrss/
Description: Example: <?php echo getFeed('http://www.website.com/feed','<li>','</li>'); ?> and then stick it in between a <ul>
Author: Jeremy Keith & Zach Inglis
Author URI: http://www.adactio.com
Version: 1.00

Based upon the original Gravatar plugin:
http://gravatar.com/implement.php#section_2_2
*/

function getFeed($feed,$before=’

  • ‘,$after=’
  • ‘) {
    $return = “”;

    $rss = new DOMDocument();

    if (!$rss -> load($feed)) {
    return $before.”Couldn’t find RSS file.”.$after;
    }

    $count = 0;

    foreach ($rss -> getElementsByTagName(”item”) as $item) {

    if ($item -> getElementsByTagName(”title”) -> item(0)) {
    $return.= $before;
    $return.= “
    $return.= $item -> getElementsByTagName(”link”) -> item(0) -> nodeValue;
    $return.= “\” title=\”View the ‘”;
    $return.= $item -> getElementsByTagName(”title”) -> item(0) -> nodeValue;
    $return.= “‘ entry \”>”;
    $return.= $item -> getElementsByTagName(”title”) -> item(0) -> nodeValue;
    $return.= “
    “;
    $return.= $after;
    $return.= “\n”;
    }

    $count ++;
    }

    if ($count == 0) {
    $return = $before.”This feed has no items.”.$after;
    }

    return $return;
    }

    ?>

    Support will be open again soon