homepage Welcome to WebmasterWorld Guest from 54.205.242.179
register, free tools, login, search, subscribe, help, library, announcements, recent posts, open posts,
Subscribe to WebmasterWorld

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

RSS, ATOM, and Related Technologies Forum

    
One site, multiple RSS feeds. Must be a better way
Must I make new sub-pages for each feed?
revtim




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

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!

 

eelixduppy




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

>> 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.

revtim




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

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?

eelixduppy




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

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';
include_once('feed.php');

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];
include_once('feed.php');
} 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 :)

eelixduppy




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

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 ;)

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.
Terms of Service ¦ Privacy Policy ¦ Report Problem ¦ About
© Webmaster World 1996-2014 all rights reserved