homepage Welcome to WebmasterWorld Guest from 54.166.128.254
register, free tools, login, search, pro membership, help, library, announcements, recent posts, open posts,
Become a Pro Member

Home / Forums Index / Code, Content, and Presentation / RSS, ATOM, and Related Technologies
Forum Library, Charter, Moderators: bill & werty

RSS, ATOM, and Related Technologies Forum

    
Placing a RSS feed on my site
Things to do
anand84

WebmasterWorld Senior Member 5+ Year Member



 
Msg#: 464 posted 6:35 pm on Jan 21, 2006 (gmt 0)

Hi

After a lot of thinking on what to have on my homepage, I have now decided on having a RSS feed from Google News besides a few articles, etc.

When I checked out Google feed, it is inside <rss>..</rss> tags. I would like to know how I can include them in my HTML page.

Also, should I enter the code inside a table so that it remains where I want it to be or is there some other procedure.

Thanks.

 

triso

5+ Year Member



 
Msg#: 464 posted 4:10 am on Jan 24, 2006 (gmt 0)

I have used rss feeds extensively on my sites and they are great. I have not used Google News in favour of other providers and news relevant to my sites.

I build all my sites in php and so process the xml feed with php to produce the html that is viewed on the page. If you have a basic understanding of php you could implement the code in your page (provided your page extensions are .php not .html and your server has php). I'm happy to share.

In terms of placing it on your page it depends on whether you are using css or a tabled design. I exclusively use css and minimise tables altogether. In css you just put the feed in a div and define the width, position etc in the stylesheet.

anand84

WebmasterWorld Senior Member 5+ Year Member



 
Msg#: 464 posted 4:01 pm on Jan 24, 2006 (gmt 0)

thanks for the info triso..Yes, I know a very basic form pf php.

So, do I simply place the <rss>...</rss> code inside the php part of my .php page? will that suffice?

triso

5+ Year Member



 
Msg#: 464 posted 10:29 pm on Jan 24, 2006 (gmt 0)

What you need to do is to parse the rss feed that is in xml format to html. the xml at url news.google.com/news?ned=us&topic=t&output=rss is delineated by tags in the same way as html is.
each item has the following tags:

<item>
<title></title>
<link></link>
<guid isPermaLink="false"></guid>
<pubDate></pubDate>
<description></description>
</item>

php has a series of functions for parsing xml (check out php.net). the code I use to parse xml feeds is below. It is not as good as some other peoples code, but it works for the feeds I use. you may need to modify the code for google news, I have not used google news feeds.

just enter the url for the feed in the spot where i have --enter url for news feed here-- and you can change the number of news items and the length of th description also easily.


<?

$MAXLINKCOUNT = 10; // (* 2) if =10, 5 news items will show
$MAX_DESC_CHARS = 120;

$insideitem = false;
$tag = "";
$title = "";
$description = "";
$link = "";
$linkcount = 0;

function startElement($parser, $name, $attrs) {
global $insideitem, $tag, $title, $description, $link;
if ($insideitem) {
$tag = $name;
} elseif ($name == "ITEM") {
$insideitem = true;
}
}

function endElement($parser, $name) {

global $insideitem, $tag, $title, $description, $link, $linkcount, $MAXLINKCOUNT, $MAX_DESC_CHARS;
if ($name == "ITEM" && $linkcount <= $MAXLINKCOUNT) {
if (strlen($description) > $MAX_DESC_CHARS) {
$description = wordwrap($description, $MAX_DESC_CHARS, "-=CUT OFF HERE=-");
$pos = strpos($description, "-=CUT OFF HERE=-");
$description = trim(substr($description, 0, $pos)) . "...";
}
$description = htmlspecialchars(trim($description));
$description = str_replace("&amp;quot;", "&quot;", $description);
printf("<dt><b><a href='%s'>%s</a></b></dt>", trim($link),htmlspecialchars(trim($title)));
printf("<dt>%s</dt><br>",$description);
$title = "";
$description = "";
$link = "";
$insideitem = false;
}
}

function characterData($parser, $data) {
global $insideitem, $tag, $title, $description, $link, $linkcount;
if ($insideitem) {
switch ($tag) {
case "TITLE":
$title .= $data;
break;
case "DESCRIPTION":
$description .= $data;
break;
case "LINK":
$link .= $data;
$linkcount++;
break;
}
}
}
$xml_parser = xml_parser_create();
xml_set_element_handler($xml_parser, "startElement", "endElement");
xml_set_character_data_handler($xml_parser, "characterData");
$fp = fopen("--enter url for news feed here--","r")
or die("Error reading RSS data.");
while ($data = fread($fp, 2048)) {
xml_parse($xml_parser, $data, feof($fp));
}
fclose($fp);
xml_parser_free($xml_parser);

?>

Kahless

10+ Year Member



 
Msg#: 464 posted 2:12 am on Jan 25, 2006 (gmt 0)

Webreference has a good tutorial and a script for converting RSS to HTML in perl. Just go to their site at search for rss2html

I am not sure if it removes the html but if you want a clean rss feed from most major and international news sites you can try the ones over at newslookup in the feeds section.

dimensioni

5+ Year Member



 
Msg#: 464 posted 7:28 am on Jan 25, 2006 (gmt 0)

Is this how you display Scrolling news on your site...If not please let me know how I can display the scrolling news sepcific to my domain on my site.

I understand I need to create a database to store the feeds and then display it..right?

burf2000

5+ Year Member



 
Msg#: 464 posted 9:36 am on Jan 25, 2006 (gmt 0)

Did anyone try the php script as this looks really interesting / easy and if no one has tried it, I will try it today and report back!

triso

5+ Year Member



 
Msg#: 464 posted 10:00 am on Jan 25, 2006 (gmt 0)

I'm not sure what you mean by 'scrolling news'. I have not heard the term. This script simply parses a news feed of your choice to html. You can select a feed that is specifically relevant to your site.

The feed works really well for feeds that do not include html in the description tag. If the feed you want to use uses html in the description (like Google news) then you will need to edit the script.

rincey

10+ Year Member



 
Msg#: 464 posted 10:13 am on Jan 25, 2006 (gmt 0)

I use magpierss, a free PHP library that does all the work. Very easy to install. Just unpack the archive and move it into a subdirectory.

Typical use is

require_once("magpierss/rss_fetch.inc");
$url = "http://rss.news.yahoo.com/rss/world";
$rss = fetch_rss($url);

Returned value $rss is an object with feed data and all items in an array. magpierss also has a built-in cache functionality.

dimensioni

5+ Year Member



 
Msg#: 464 posted 10:24 am on Jan 25, 2006 (gmt 0)

when I say scrolling means, the news section is in a little box where the oldest news keep moving up and newest one pushes from below giving the impression that the whole text is scrolling upword.

I'm sure you must have seen on some sites specially project bidding sites where new project posted keep coming from below in side a box and old project move up.

anand84

WebmasterWorld Senior Member 5+ Year Member



 
Msg#: 464 posted 2:33 pm on Jan 26, 2006 (gmt 0)

That was quite good piece of info from you people. I am still in the process of designing my pages and shall be including the RSS feed page very shortly. Thanks for all your help, and keep including other ways to include RSS feeds.

Global Options:
 top home search open messages active posts  
 

Home / Forums Index / Code, Content, and Presentation / RSS, ATOM, and Related Technologies
rss feed

All trademarks and copyrights held by respective owners. Member comments are owned by the poster.
Home ¦ Free Tools ¦ Terms of Service ¦ Privacy Policy ¦ Report Problem ¦ About ¦ Library ¦ Newsletter
WebmasterWorld is a Developer Shed Community owned by Jim Boykin.
© Webmaster World 1996-2014 all rights reserved