Sponsored Links

Go Back   WebMasters.org Forums > Blogging > Blogging Forum

Reply
 
LinkBack Thread Tools Display Modes
  #1 (permalink)  
Old 06-07-2007, 03:22 AM
ITGuy ITGuy is offline
Junior Member
 
Join Date: May 2007
Posts: 18
Default RSS, Is it Really That Great?

Since I really am not that familiar with running a Blog and have only been involved with them for a year or so, I have a question about RSS. What is it? From the information I gather, it is a type of news feed. You subscribe to a Blog that interests you and updated information is sent to you via another program. It seems a bit like the old fashioned newsgroups that everyone used to be involved in. Does anyone have other information about RSS?
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #2 (permalink)  
Old 06-16-2007, 12:39 AM
newway newway is offline
Junior Member
 
Join Date: May 2007
Posts: 23
Default

You have got a correct idea. You will understand that more if you use that. Use some RSS feeds of some sites and also use it on your sites. Here I am giving a Short guide to add RSS in your site. I got it from another site.
Including RSS feeds in to your own pages is pretty simple with PHP and some open source libraries. The follwing lines show how to create HTML from RSS feeds using the popular PHP tools magpierss (fetches and parses the RSS feed) and Smarty (template engine).

It may look like overkill to use such powerful tools for such a simple task. But once installed, both give a variety of functions and reduce the self-written code to a few lines.

Here we go:

A. Preparing the Webhost/Server

A current version of PHP is necessary. The following tutorial assumes that all files are placed in the folder /rssdemo on your web host.

1. Install magpierss RSS tool
I am not sure if I am allowed to add URLs here, so just google for "magpierss" and take the first result. Follow the DOWNLOAD link and download the recent version of magpierss (0.72 as I write this).

The file comes as .tar.gz format, so if you are on a Windows PC, you will need additional software to unzip this. I think WinZip does the job, you can also use the free tool "7-zip". The first "Extract" will make a .tar-file out of the .tar.gz, the second extraction should create a folder named magpierss-0.72.

2. Install Smarty template engine
Google for "smarty" and follow the link to php.net. Download the the recent version of Smarty (2.6.12 as I write this).

The file also comes as .tar.gz format, after extraction there should be a folder named Smarty-2.6.12.

3. Rename folders and move them to /rssdemo
Whereever you extracted both folders, now it is time to move them. First delete the version numbers out of the folder names. Change magpierss-0.72 to magpierss and Smarty-2.6.12 to Smarty. Move both folders into the /rssdemo folder on your local test server or upload them to your web server.

4. Smarty needs some special folders.
Please create the following folders in the /rssdemo folder:
- cache
- configs
- templates
- templates_c
The last one, templates_c, needs to have write permission for Smarty. If your webhost is on Unix, set the permissions as needed (777 in the worst case, depends on server config).

B. A few lines of PHP for parsing and displaying the feed.

Now, with all the installation work done, we only need a few more lines of code for our task. Place the follwing code in a file named feed.php in the /rssdemo folder.

------------------

<?
/* The folder where this file is located. Change to whatever you need */
$mydir = "/rssdemo";

/* Include magpierss and Smarty library */
require_once($_SERVER["DOCUMENT_ROOT"].$mydir."/Smarty/libs/Smarty.class.php");
require_once($_SERVER["DOCUMENT_ROOT"].$mydir."/magpierss/rss_fetch.inc");

/* Create a template object for further use */
$tpl = new Smarty();

/* Set folders for Smarty object. This folders have to exist on your web server (Check A.3) */
$tpl->template_dir = $_SERVER["DOCUMENT_ROOT"].$mydir.'/templates/';
$tpl->compile_dir = $_SERVER["DOCUMENT_ROOT"].$mydir.'/templates_c/';
$tpl->config_dir = $_SERVER["DOCUMENT_ROOT"].$mydir.'/configs/';
$tpl->cache_dir = $_SERVER["DOCUMENT_ROOT"].$mydir.'/cache/';

/* The URL of the feed we want to include */
$url = "http://rss.news.yahoo.com/rss/world";

/* magpierss does all the work! */
$rss = fetch_rss($url);

/* Uncomment the following line to see the object and array data returned. Good to see which other information has been processed by magpierss */
// echo "<pre>"; print_r($rss); echo "</pre>";

/* If the RSS could be parsed, add it to the template */
if ($rss) {
/* Sends the feed title to the template engine */
$tpl->assign("feedtitle",$rss->channel["title"]);
/* Sends the RSS items as an array */
$tpl->assign("items",$rss->items);
}
else {
/* RSS problem? */
$tpl->assign("feedtitle","Problem with: $url");
}

/* Fill the template file itemlist.html with the information and return it */
$feedhtml = $tpl->fetch($_SERVER["DOCUMENT_ROOT"].$mydir."/templates/itemlist.html");
/* Do with $feedhtml whatever you want */
echo $feedhtml;
?>


------------------

C. We need a template!

Smarty is a very powerful template engine which makes creating tables and lists a snap. For this demo we need a simple template that prints the name of the feed in the title and lists the items.

Copy the following lines into a file named "itemlist.html" and save it in the /rssdemo/templates folder.

------------------

{* very simple template for a table with RSS items *}
<table>
{* Show the feed title as a header in the first row of the table *}
<tr><th style="font-size: 24px; border: 1px solid black;">{$feedtitle}</th></tr>
{* loop through all items and add date, link, title and description in the follwing section *}
{section name=x loop=$items}
<tr><td class="rssitem" style="border: 1px solid red;">
<strong>{$items[x].pubdate}: <a href="{$items[x].link}" target="_blank">{$items[x].title}</a></strong><br>
{$items[x].description}
</td></tr>
{/section}
</table>
{* That's it. Table can be formatted using some CSS classes *}


------------------

D. Putting it all together

Now browse to the URL /rssdemo/feed.php on your web server. The feed should be displayed with some red lines around each item.

E. Serious usage

Usually you want to include the feed output somewhere into your page. The simplest way is the name your pages .php instead of .html and add the follwing line where the feed html should be displayed.

<? include "rssdemo/feed.php"?>

e.g. like this

<table>
<tr>
<td width="80%">Left column with some information</td>
<td>Right column contains the feed<br /> <? include "rssdemo/feed.php"?></td>
</tr>
</table>

If you can't or don't want to rename your existing files, you could force your webserver to parse even .html-files for PHP code. If you use Apache, you could add the "AddType application/x-httpd-php .php .html" to your .htaccess. But this is another story.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #3 (permalink)  
Old 06-19-2007, 09:26 AM
finalcall finalcall is offline
Junior Member
 
Join Date: May 2007
Posts: 24
Default

you can learn more about RSS at Making An RSS Feed.
chk it out.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #4 (permalink)  
Old 06-23-2007, 05:45 PM
coolmaster coolmaster is offline
Junior Member
 
Join Date: May 2007
Posts: 25
Default

oh. that is a good one. thanks for that.keep posting more.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #5 (permalink)  
Old 03-22-2008, 10:28 AM
falguni1 falguni1 is offline
Junior Member
 
Join Date: Mar 2008
Posts: 26
Default

the more people subscribe to your site via rss the more popular it gets. if you give full feed rss you can place ads in it via feedburner.
__________________
my site

www.oamsites.com
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #6 (permalink)  
Old 03-23-2008, 07:27 PM
Aspire7 Aspire7 is offline
Junior Member
 
Join Date: Mar 2008
Posts: 25
Default

It's like informing your loyal fans that you have something new upcoming. If you add an update to your blog, your subscriber will be immediately informed. RSS feed is a must these days.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #7 (permalink)  
Old 03-24-2008, 08:32 AM
Jasmine Jasmine is offline
Junior Member
 
Join Date: Mar 2008
Posts: 24
Default

Some people use feeds to get contents for their website. Just remember to give credit to the original writer or get the person's permission and acknowledgment.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On



All times are GMT. The time now is 04:02 PM.


Sponsored Links

Powered by vBulletin® Version 3.6.7
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
SEO by vBSEO 3.0.0
vB Ad Management by =RedTyger=