Installing SimplePie RSS

OVERVIEW:

The SimplePie RSS application allows news feeds to be displayed on a web page.

REQUIREMENTS:

  1. The display page must be a PHP file.
  2. A writable cache folder needs to created.

INSTALLATION:

The following code needs to be placed at the very beginning of the PHP-based display page.

<?php
require_once('../path/to/simplepie/simplepie.inc');
$feed = new SimplePie('http://news-source.tld/feed.file');
$feed->handle_content_type();
?>

A writable folder named cache must be created in the same directory as the folder that contains the simplepie.inc file.

drwxrwxrwx  user group cache
drwxr-xr-x  user group simplepie

The application must be called from within the display page.  Below is a snippet from the SimplePie website.

    <div class="header">
        <h1><a href="<?php echo $feed->get_permalink(); ?>"><?php echo $feed->get_title(); ?></a></h1>
        <p><?php echo $feed->get_description(); ?></p>
    </div>

    <?php
    /*
    Here, we'll loop through all of the items in the feed, and $item represents the current item in the loop.
    */
    foreach ($feed->get_items() as $item):
    ?>

        <div class="item">
            <h2><a href="<?php echo $item->get_permalink(); ?>"><?php echo $item->get_title(); ?></a></h2>
            <p><?php echo $item->get_description(); ?></p>
            <p><small>Posted on <?php echo $item->get_date('j F Y | g:i a'); ?></small></p>
        </div>

    <?php endforeach; ?>

REFERENCES:

Advertisements

Tags:

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

w

Connecting to %s


%d bloggers like this: