AyushSaran.com

Graphic Design Web Design San Diego

   

8

Mar

Integrating RSS Feeds

This is just an excerpt of the relevant portions from the original Tutorial, which can be found at UltraEdit: WordPress RSS Fetch integration

Download RSS Fetch [Version 0.4.3 PHP4]

An RSS 2.0/0.91 feed parser. This PHP4 Class greatly simplifies displaying RSS data on your web page. It parses any valid RSS feed with tags and allows you to customize the data on your web page. It will cache feeds and update them however often you say. HTML templates allow you to include your own html code and include any tags the RSS feed contains using a custom #{tagname} variable. 0.4.3 added ability to start showing feeds from a given offset, instead of from the first.
Step 1. Unzip the Archive
Unzip the rss_fetch.zip.

Step2. Edit rss_fetch.php

Open your text editor and open rss_fetch.php (which was in the rss_fetch.zip).

You will need to change 2 variables in your rss_fetch.php.
The variables you are chaging are “$update_interval” and “$data_directory”

Edit rss_fetch

The ‘update_interval’ sets how often to fetch the rss file.

The ‘data_directory’ tells the script where to store the rss data from the feeds. If this directory does not (yet) exist you will need to create it on your server.

Note: for ‘data_directory’, an absolute path is better than a relative path here unless you plan on keeping the script to display the feeds in the same folder as this file and the feeds

Step 3: Upload the rss_fetch.php

Create a directory on your server where you would like to ‘install’ the RSS Fetch class. This could be in a separate directory or in the document root, it’s really up to you where you want to put it.

By ‘document root’ we mean the root directory for the domain. This is the location of the files for your site. For example, the ‘home page’ (ie. index.html, index.php, etc) is located in the document root directory.

For the remainder of this tutorial, we will refer to the ‘document root’ as the root directory.

Now, back to installing the RSS Fetch class. For the purposes of this tutorial we will use the following path /home/www/rss/. As you can see, we are placing the rss_fetch.php (class) in the ‘rss’ directory.

Upload the rss_fetch.php to the directory using ftp

Step 4: Add the Code to Display the Feed

Now, you will need to open the file(s) which you would like to display the feed in.

For illustration purposes, pretend we are using index.html at the root of our server.

Open index.html add the following code where you would like the feed to display:


<div>
<h2>IDM Computer Solutions, Inc. News</h2>
<?php
include_once “rss/rss_fetch.php”;
$html .= ” <h3 style=’background-color: #e3e3e3; font-weight: bold; color: #000000;’ >n”;
$html .= ” <a href=’#{link}’ target=’_new’>#{title}</a></h3>n”;
$html .= ” <p>#{description}</p>n”;
$rss = new rss_parser(”http://ultraedit.com/rss/news2.php”, 5, $html, 1);
?>
</div>

The important thing to note here is the following line: include_once “rss/rss_fetch.php”;

This line tells the server where to find the ‘rss_fetch.php’ file. If the path here is incorrect, the server will not find the file and will not display the feed.

As our ’sample’ file (index.html) is at the root of the server, the path (in the include) points to ‘rss/rss_fetch.php’.

Think of it like this, the server found index.html sitting in the same directory (which happens to be the root) as the directory named ‘rss’. In order to find rss_fetch.php (from the location of index.html), the server had to go into the rss directory first, makes sense right? If you are unsure about paths/references, there are plenty of basic HTML/PHP tutorials available online to help you with this.

Use the power of syntax highlighting to check for errors in your code. After you have added this code to your file it should look something similar to:

highlighted code

Step 5: You’re Done!

To see the feeds on your site, just open your web browser and go to the page which you added the code to.

Tags Tags for this entry:    No Tags


See Related Posts

One Response to “Integrating RSS Feeds”

Add Comment   Leave a Comment

You must be logged in to post a comment.