This is a discussion on Setting up rss feeds within the Coding Help forums, part of the Webmaster Help category; Hello, I've been trying to figure out the basics of setting up a simple rss feed from, say, the BBC, ...
| |||||||
| Register | Forum Rules | FAQ | Donate | Members List | Calendar | Search | Today's Posts | Mark Forums Read |
| ||||
| Hello, I've been trying to figure out the basics of setting up a simple rss feed from, say, the BBC, on a .php page, but having gone through umpteen articles on the net I am going round in circles. I cannot figure out what I am meant to be creating file-wise to upload to site - and where - and what actually goes in the particular page I want the feed to appear on. If anyone can help me along the way with this one I'd be very grateful. Big D. |
| |||||
| various ways you can go about this really ... url = BBC News | News Front Page | World Edition get yourself Magpie RSS - PHP RSS Parser read the documentations .. and away you go ?
__________________ Forbairt Media | Web Design & Development Galway / Dublin, Ireland - coming soon ... ( vague but descriptive isn't it ) Recent Work: Safari Club African Safari Holidays - South Africa Safaris Other Stuff: FluffyLinkulator Rapid Inclusion Service Tools |
| |||||
| should add Code: require_once 'rss_fetch.inc';
$url = 'http://magpie.sf.net/samples/imc.1-0.rdf';
$rss = fetch_rss($url);
echo "Site: ", $rss->channel['title'], "<br>
";
foreach ($rss->items as $item ) {
$title = $item[title];
$url = $item[link];
echo "<a href=$url>$title</a></li><br>
";
}
for example if you site gets hit once a minute ... that'd be 60 hits to the BBC ... if you site gets hit 10 times a minute .. it'd be 600 hits .. and so on ... so the bbc may not like you doing that You'll also be required to link back to their site / articles and give your source in most cases
__________________ Forbairt Media | Web Design & Development Galway / Dublin, Ireland - coming soon ... ( vague but descriptive isn't it ) Recent Work: Safari Club African Safari Holidays - South Africa Safaris Other Stuff: FluffyLinkulator Rapid Inclusion Service Tools |
| ||||
| Forbairt, thank you for your reply. I've just posted a message in the General chat section to explain that I've had to learn on the hoof since I lost my webmaster of 10 years, so there are still gaping holes in my knowledge. However, it looks as though Magpierss has already been placed on my site for a feed set up by my former webmaster. I notice there are 4 rss files in the directory: rss.php rss_cache.inc rss_fetch.inc rss_parse.inc and the rss.php file reads as follows: <?php require_once 'rss_fetch.inc'; $url = 'http://news.bbc.co.uk/rss/newsonline_uk_edition/northern_ireland/rss091.xml'; $rss = fetch_rss($url); $id=0; echo "Site: ", $rss->channel['title'], "<br>\n"; foreach ($rss->items as $item ) { if($id=="5") { echo "</td><td><p>\n"; } if($id=="10") { echo "</td><td><p>\n"; } if($id=="15") { break; } $id++; $title = $item[title]; $url = $item[link]; $description = $item[description]; echo "<a href=$url>$title</a><br>$description</li><br>\n"; } ?> What I can't figure out is what code I should put in the page on which I would like the feed to appear, i.e. how do I activate the feed on a given web page? |
| |||||
| create a new file just to test its all working "filename.php" put all your code into it I've simplified it slightly ... I think this code was being included as part of another file. Code: <?php
require_once 'rss_fetch.inc';
$url = 'http://news.bbc.co.uk/rss/newsonline_uk_edition/northern_ireland/rss091.xml';
$rss = fetch_rss($url);
echo "Site: ", $rss->channel['title'], "<br>\n";
foreach ($rss->items as $item ) {
$title = $item[title];
$url = $item[link];
$description = $item[description];
echo "<a href=$url>$title</a><br>$description</li><br>\n";
}
?>
anywhere you want this to appear you could just put the code <?PHP include "filename.php"; ?>
__________________ Forbairt Media | Web Design & Development Galway / Dublin, Ireland - coming soon ... ( vague but descriptive isn't it ) Recent Work: Safari Club African Safari Holidays - South Africa Safaris Other Stuff: FluffyLinkulator Rapid Inclusion Service Tools |
| ||||
| Forbairt, thank you very much for that - I have it working! Just a couple of quickies: 1. Can these feeds be styled with css? 2. Presumably the feed source can simply be changed by changing the URL? |
| |||||
| Quote:
Code: echo "<a href=$url>$title</a><br>$description</li><br>\n"; Code: <div class="rssFeed"> ... ... </div> I'd almost recommend you remove the $url bit from your include file then when ever you want to include a rss feed Code: <?PHP $url = "http://www.myurlformyrssfeed.com/my.rss"; include "filename.php" ?>
__________________ Forbairt Media | Web Design & Development Galway / Dublin, Ireland - coming soon ... ( vague but descriptive isn't it ) Recent Work: Safari Club African Safari Holidays - South Africa Safaris Other Stuff: FluffyLinkulator Rapid Inclusion Service Tools |
| ||||
| Right, I've managed to get the thing going and have styled it a bit with css, but the feed is pretty long - what way - if any - is there of controlling the number of items in the feed? Until I get familiar with what each piece of the code does and get more adept at rss feeds generally I will almost certainly require more help, but I have to say that I do really appreciate your helpfulness. To show my good faith in the meantime would a link from my website Library Ireland: Irish History and Culture to your site be of any use? Big D. |
| |||||
| Quote:
Code: $rss = fetch_rss($url); $items = array_slice($rss->items, 0, 5); A link wouldn't hurt but isn't necessary
__________________ Forbairt Media | Web Design & Development Galway / Dublin, Ireland - coming soon ... ( vague but descriptive isn't it ) Recent Work: Safari Club African Safari Holidays - South Africa Safaris Other Stuff: FluffyLinkulator Rapid Inclusion Service Tools |
| ||||
| Forbairt, The array slice line hasn't affected the length of the feed - don't know whether I've done something wrong?-- Code: <?php
require_once 'rss_fetch.inc';
$url = 'http://news.bbc.co.uk/rss/newsonline_uk_edition/northern_ireland/rss091.xml';
$rss = fetch_rss($url);
$items = array_slice($rss->items, 0, 5);
echo "Site: ", $rss->channel['title'], "<br>\n";
foreach ($rss->items as $item ) {
$title = $item[title];
$url = $item[link];
$description = $item[description];
echo "<a href=$url>$title</a><br>$description</li><br>\n";
}
?>
|
| Tags |
| feeds, rss, setting |
| Thread Tools | |
| Display Modes | |
|
|
| ||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| rss feed or newsletter | Busarus | Webmaster Discussion | 4 | 02-03-2007 09:29 PM |
| RSS feeds | ph3n0m | Forum Feedback, Development and Competitions | 6 | 31-01-2007 12:39 AM |
| 1 Bag of RSS feed: 100% RDA of internet. Warning: may contain nut traces. | gary.b | General Chat | 15 | 29-01-2007 10:03 PM |
| Web RSS readers | Cormac | Webmaster Discussion | 3 | 18-10-2006 01:26 PM |
| rss feed | louie | General Chat | 0 | 29-04-2006 08:18 PM |