Click to See Complete Forum and Search --> : [RESOLVED] Help me limit RSS Feed


jazzyj99
04-26-2006, 01:01 AM
Is there any way I can modify the following code to only limit 5 items and then have a link where the user can click to see the remaining feeds from the rss??

Thanks,

Jeff

<?php
require_once '../magpierss/rss_fetch.inc';

$url = 'http://news.google.com/news?hl=en&ie=UTF-8&q=compliance&btnG=Search+News&output=rss' ;

$rss = fetch_rss($url);

echo 'Site: ' , $rss->channel['title'], ' <br / >';
if ( $rss and !$rss->ERROR) {
foreach ($rss->items as $item ) {
echo ' <p class=text><a href="' . $item[link] . '">' . $item[title] . ' </a><br / >';
echo 'Publish Date: ' . $item[pubdate] . ' <br / >';
echo $item[ description ] . ' </p>' ;
}
} else {
echo 'RSS Error: ' . $rss->ERROR . ' <br / ><br />' ;
}
?>

NogDog
04-26-2006, 07:44 AM
<?php
if ( $rss and !$rss->ERROR) {
$counter == 0; // use to track how many items we've displayed
foreach ($rss->items as $item ) {
if(++$counter >= 5)
{
echo "<p><a href='link_to_all_items'>See more...</a></p>\n";
break; // break out of foreach loop
}
echo ' <p class=text><a href="' . $item[link] . '">' . $item[title] . ' </a><br / >';
echo 'Publish Date: ' . $item[pubdate] . ' <br / >';
echo $item[ description ] . ' </p>' ;
}
}
?>

jazzyj99
04-26-2006, 11:51 AM
That's exactly what I needed:)