Welcome to WebmasterWorld Guest from

Forum Moderators: bill & werty

Message Too Old, No Replies

One site, multiple RSS feeds. Must be a better way

Must I make new sub-pages for each feed?



1:33 pm on Jun 23, 2008 (gmt 0)

5+ Year Member

I have used your handy Guide for installing RSS on a PHP page [webmasterworld.com ]

and it is working fine. Using this method, I install two "subpages" which support the eventual public page, the feed.php and itemlist.html pages.

Now I want to install different feeds on 7 different pages on my site. Do I need to make pages feed1.php through feed7.php and itemlist1.html through itemlist7.html to support these individual feeds or is there a more effective way to accomplish this objective?

Thanks for the help so far. Finally I am making progress and it feels great!


1:56 am on Jun 24, 2008 (gmt 0)

WebmasterWorld Senior Member eelixduppy is a WebmasterWorld Top Contributor of All Time 10+ Year Member

>> different feeds on 7 different pages

Create one feed.php page to handle multiple feeds when requested. You might need to pass an appropriate value to it via a GET method (URL query) however that would be the way I'd do it. It would save a lot of recoding the same thing but changing a few specific values.


11:48 am on Jun 24, 2008 (gmt 0)

5+ Year Member

As I have some charts wherein I enter a query on the public page and it accesses the php form and creates the result, I figured the same could be true here, which you confirm. The problem is, I have no idea how to alter the code so the feed page becomes a tool for the public page and I alter the feed via the code I put into the public page instead of simply putting <? include "rssdemo/feed.php"?> into the code.

Would I enter the entire feed.php code into my public page instead of accessing it in the current way? If no, how would I set it up? Also, what about the "itemlist.html" page. That has a title I need to change with each page. Can I make it with a query too?


8:55 am on Jun 27, 2008 (gmt 0)

WebmasterWorld Senior Member eelixduppy is a WebmasterWorld Top Contributor of All Time 10+ Year Member

The way you have it setup now is going to stay pretty much the same. There are two things that you have to change from feed to feed, and that is 1) the actual RSS URL itself and 2) the template you are going to use for that particular feed.

As far as modifications go for the feed.php file, I would do the following:

Remove this line:

$url = "http://rss.example.com";

Change this line:

$feedhtml = $tpl->fetch($_SERVER["DOCUMENT_ROOT"].$mydir."/templates/itemlist.html");

To something like this:

$feedhtml = $tpl->fetch($_SERVER["DOCUMENT_ROOT"].$mydir."/templates/" . [b]$template[/b]);

Now, in whatever page you are going to be including this feed.php file from, you have to first make sure to define a few variables. Now, statically it would look something like this:

# Declare the variables before the include
$url = 'http://rss.example.com';
$template = 'temp.html';

For multiple feeds, however, you are going to want both the template and the URL to be changeable. From what I've read, you are going to be submitting a form for this, so maybe out of a few possible RSS feed options, you could have something like the following:

$feeds = array('example1' => array('http://rss.example1.com', 'temp1.html'),
'example2' => array('http://rss.example2.com', 'temp2.html'),
'example3' => array('http://rss.example3.com', 'temp2.html')
# Then, assuming the POSTed data comes in at $_POST['feed']
# check to see if the submitted feed is in array
if(in_array($_POST['feed'], $feeds)) {
$url = $feeds[$_POST['feed']][0];
$template = $feeds[$_POST['feed']][1];
} else { # error
echo 'You have submitted an incorrect feed. Please try again.';

This should at least get you started if nothing else. I just wrote this up real quick without testing it so I hope it does actually work. good luck :)


12:52 pm on Jun 27, 2008 (gmt 0)

WebmasterWorld Senior Member eelixduppy is a WebmasterWorld Top Contributor of All Time 10+ Year Member

In case you want to use my example code, there's a little amendment here that needs to be fixed for the code to work properly. Change this line:

if(in_array($_POST['feed'], $feeds)) {

To this:

if(array_key_exists($_POST['feed'], $feeds)) {

Posting at 5am does that to ya ;)


Featured Threads

Hot Threads This Week

Hot Threads This Month