You are here:  » More than 1 RSS Feed

Support Forum



More than 1 RSS Feed

Submitted by hutchinsonm on Wed, 2010-07-28 15:49 in

David,

I just wanted to know if it is possible to put more than 1 RSS feed onto a single page.

I have more than a dozen RSS feeds and would like them all to post to one page or a set of pages numbered at the bottom. Is this possible?

Thanks

Matt

Submitted by support on Wed, 2010-07-28 15:58

Hi Matt,

I wouldn't recommend parsing more than one RSS feed in real time into a page - and ideally they should be cached on your server over a reasonable period to avoid making a request to the server providing the RSS feed for every request of your page - although if the RSS files are saved locally, that's fine. Perhaps it's best to work on an example on that basis; and then look at other ways to automate the retrieval of your RSS feeds if you need to do that.

Assuming that you create a folder called rss/ within your Price Tapestry installation folder, the following code will display all items in each feed listed in an array of feeds; with a link to "Next" if there are more to display. Have a go with something like this; which I've based on the Magic Parser BBC News example:

<?php
  
require("includes/common.php");
  require(
"includes/MagicParser.php");
  function 
myRecordHandler($item)
  {
    print 
"<h2><a href='".$item["LINK"]."'>".$item["TITLE"]."</a></h2>";
    print 
"<p>".$item["DESCRIPTION"]."</p>";
  }
  require(
"html/header.php");
  
$rss = array();
  
$rss[] = "rss/feed1.xml";
  
$rss[] = "rss/feed2.xml";
  
$rss[] = "rss/feed3.xml";
  
$rss[] = "rss/feed4.xml";
  
$page = ($_GET["page"]?$_GET["page"]:1);
  
MagicParser_parse($rss[$page],"myRecordHandler","xml|RSS/CHANNEL/ITEM/");
  if (
$page count($rss))
  {
    print 
"<p><a href='?page=".($page+1)."'>Next</a></p>";
  }
  require(
"html/footer.php");
?>

Although having said that - if all the feeds are on your server then all on one page is no problem...!

<?php
  
require("includes/common.php");
  require(
"includes/MagicParser.php");
  function 
myRecordHandler($item)
  {
    print 
"<h2><a href='".$item["LINK"]."'>".$item["TITLE"]."</a></h2>";
    print 
"<p>".$item["DESCRIPTION"]."</p>";
  }
  require(
"html/header.php");
  
$rss = array();
  
$rss[] = "rss/feed1.xml";
  
$rss[] = "rss/feed2.xml";
  
$rss[] = "rss/feed3.xml";
  
$rss[] = "rss/feed4.xml";
  foreach(
$rss as $feed)
  {
    
MagicParser_parse($feed,"myRecordHandler","xml|RSS/CHANNEL/ITEM/");
  }
  require(
"html/footer.php");
?>

Hope this points you in the right direction!

Cheers,
David.

Submitted by hutchinsonm on Wed, 2010-07-28 17:16

David,

I followed the first example that you had given. I am not sure what the issue is because it is now throwing any errors. I put the feed into a file per the example and into the rss directory. When I go to the PHP file I created I do not see any of the Feed, only the "Next". I did check to see if there was anything to display and in the 4 test files I used there was when I want to the actual feed.

Thanks

Matt