Recipe 6.7. Embedding RSS Feeds on Your Site


Problem

You want to add another web site's content, such as news headlines, to your web site.

Solution

Get the URL of the RSS feed you want to syndicate, and then use one of the many feed parsing tools to reformat the entries in the feed as HTML for display on your site.

Discussion

RSS, which stands for Rich Site Summary or Really Simple Syndication, is a file format that facilitates the sharing and syndication of web site content. RSS files typically contain 10 to 25 entries, each with a headline, short description, and a link to more information about the entry on the parent web site. RSS files are structurally similar to web pages, but use XML tags instead of HTML. The RSS file format is discussed in more detail in Recipe 6.8.

Always make sure you have the publisher's permission to syndicate their feed on your site. And never pass off someone else's content as your ownlest you be accused of "feed hijacking" or "blog plagiarism."


The number of RSS feeds has grown rapidly during the last couple of years. Nearly every major news operation, blog, and high-traffic specialty site offers its frequently updated content as a feed. RSS feeds are popular because of their potential: they have been anointed as an antidote to spam and heralded as a way to harness the Web's daily deluge of information. Feeds also scale down nicely for display on small-screen mobile devices. And, of course, they provide a new vehicle for driving traffic to the publisher's web site.

Web surfers can subscribe to one or more feeds using a variety of online aggregators and PC newsreader applications that can open a feed file and parse the XML code into a human-readable format. Your web site also can subscribe to a feed using a script to reformat the feed as HTML. Feed2JS (which uses JavaScript) and Caching RSS Parser (CaRP) (which uses PHP) are just two of the many scripts you can download and use on your web site for this purpose.

To use Feed2JS, you enter the feed URL and information about how you want the feed to be displayed into a form on the Feed2JS web site. You can specify options such as the number of entries to display at one time, the length of the description (or none at all), and a CSS "hook" that lets you tweak the display using your own style sheet. The form then generates customized JavaScript code that you can copy into the body of your web page where you want to display the feed. The script itself is stored on the Feed2JS web server (or one of its mirror sites), and, like all client-side scripting, requires that the visitor's browser have JavaScript enabled for it to work.

The server-side script CaRP is a commercial RSS feed parser written in PHP (a freeware version also is available). To use CaRP, you have to download the scripts and copy them to your web server. The extra effort pays off in the form of many more configuration options, compared to Feed2JS. With CaRP, you can specify all the display options available with Feed2JS, as well as aggregate multiple feeds into one list, cache feed information to speed download time, filter feed entries by their subject, and censor offensive words. And unlike JavaScript solutions, there is no browser-side requirement for viewing the HTML feeds created with CaRP (see Figure 6-5).

See Also

For more information about the RSS feed converters discussed in this Recipe, visit their web sites: Feed2JS (http://jade.mcli.dist.maricopa.edu/feed) and CaRP (http://www.geckotribe.com/rss/carp). For a tutorial on installing and using a Perl script to convert feeds to HTML, see http://webreference.com/perl/tutorial/8. Universal Feed Parser is RSS parser written in Python (http://feedparser.org). Several sites provide directories of RSS feeds, including Feedster (http://www.feedster.com), Bloglines (http://bloglines.com), and 2RSS.com (http://www.2rss.com)



Web Site Cookbook.
Web Site Cookbook: Solutions & Examples for Building and Administering Your Web Site (Cookbooks (OReilly))
ISBN: 0596101090
EAN: 2147483647
Year: N/A
Pages: 144
Authors: Doug Addison

Similar book on Amazon

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net