PDA

View Full Version : Creating my own page w/ RSS. Need help


MikeeX
12-11-2004, 11:19 PM
Hello everyone! Hopefully I'm in the right forum :)

What I'm trying to do is setup my own vb powered page with RSS feeds on it. Now I created my php file and the template. You can view it here:

http://forums.winforums.org/technews.php

I'm using Magpie to parse the RSS. Now I have a file called technewsdata.php which is called from a varible in my phpinclude_start template.

technewsdata.php

<?

require_once 'rss_fetch.inc';

$url = 'http://rssnewsapps.ziffdavis.com/tech.xml';
$rss = fetch_rss($url);

echo "Site: ", $rss->channel['title'], "<br>\n";
foreach ($rss->items as $item ) {
$title = $item[title];
$url = $item[link];
echo "<a href=$url>$title</a></li><br>\n";
}

?>


As you can see, this works perfect (check out link posted above). Now, I want to add about 5-10 more RSS feeds like this to the same page. Now I don't know PHP at all, so I'm not sure how to accomplish this. How can I use the ONE technewsdata.php file for all my RSS feeds? Is it called an array? That's where I'm hoping you guys could help me. So I don't have to create say, technewsdata_slashdot.php, with the same parse information above. I want to utilize one php file.

I hope this makes sense, and if not let me know what else you need from me.

Any help or information on this would be greatly appreciated!

AN-net
12-11-2004, 11:23 PM
there some nice php rss tutorials out there, you can look in the external.php file for ideas and also on google;)

MikeeX
12-11-2004, 11:25 PM
external.php would be used if I wanted to use to create my own RSS correct? I'm asking pretty much how can I use php code all in one file, w/ multiple RSS feeds added to it.

Or...am I missing something?

MikeeX
03-08-2005, 02:52 PM
Thought I would post what I did. Just in case others are interested


<?

require_once 'rss_fetch.inc';

// Section 1

echo '<table cellspacing="7" cellpadding="7" width="100%">';

// RSS 1

$url1 = 'URL TO RSS';
$num_items1 = 7;
$rss1 = fetch_rss($url1);

if ( $rss1 ) {

}
else {
echo "Error reading news feed " .
"Check back later" .
"<br>Error Message: " . magpie_error();
}

echo '<tr>';
echo '<td valign="top">';
echo "&nbsp;&nbsp;Source: <b>", $rss1->channel['title'], "</b><p>\n";
$items1 = array_slice($rss1->items, 0, $num_items1);
foreach ( $items1 as $item1 ) {
$title1 = substr($item1[title], 0, 50);
//$title1 = $item1[title];
$url1 = $item1[link];
echo "? <a href=$url1>$title1</a></li><br>\n";
}
echo '</td>';
echo '<td valign="top">';

// RSS 2

$url2 = 'URL TO RSS';
$num_items2 = 7;
$rss2 = fetch_rss($url2);

if ( $rss2 ) {

}
else {
echo "Error reading news feed " .
"Check back later" .
"<br>Error Message: " . magpie_error();
}


echo "&nbsp;&nbsp;Source: <b>", $rss2->channel['title'], "</b><p>\n";
$items2 = array_slice($rss2->items, 0, $num_items2);
foreach ( $items2 as $item2 ) {
$title2 = substr($item2[title], 0, 50);
//$title2 = $item2[title];
$url2 = $item2[link];
echo "? <a href=$url2>$title2</a></li><br>\n";
}
echo '</td>';
echo '</tr>';
echo '</table>';

// Section 2

echo '<table cellspacing="7" cellpadding="7" width="100%">';

// RSS 3

$url3 = ' URL TO RSS';
$num_items3 = 7;
$rss3 = fetch_rss($url3);

if ( $rss3 ) {

}
else {
echo "Error reading news feed " .
"Check back later" .
"<br>Error Message: " . magpie_error();
}

echo '<tr>';
echo '<td valign="top">';
echo "&nbsp;&nbsp;Source: <b>", $rss3->channel['title'], "</b><p>\n";
$items3 = array_slice($rss3->items, 0, $num_items3);
foreach ( $items3 as $item3 ) {
$title3 = substr($item3[title], 0, 50);
//$title3 = $item3[title];
$url3 = $item3[link];
echo "? <a href=$url3>$title3</a></li><br>\n";
}
echo '</td>';
echo '<td valign="top">';

// RSS 4

$url4 = 'URL TO RSS';
$num_items4 = 7;
$rss4 = fetch_rss($url4);

if ( $rss4 ) {

}
else {
echo "Error reading news feed " .
"Check back later" .
"<br>Error Message: " . magpie_error();
}


echo "&nbsp;&nbsp;Source: <b>", $rss4->channel['title'], "</b><p>\n";
$items4 = array_slice($rss4->items, 0, $num_items4);
foreach ( $items4 as $item4 ) {
$title4 = substr($item4[title], 0, 50);
//$title4 = $item4[title];
$url4 = $item4[link];
echo "? <a href=$url4>$title4</a></li><br>\n";
}
echo '</td>';
echo '</tr>';
echo '</table>';

?>