Welcome to WebmasterWorld Guest from 23.20.137.66

Forum Moderators: bill & werty

Message Too Old, No Replies

Posting only the first news articles as opposed to all of them.

rss php for each but for first?

     
5:10 pm on Jun 15, 2005 (gmt 0)

10+ Year Member



Hey I'm using magpie and it works and everything, but i want to only display the first article not all of them..
here's my php code
<?php
require_once 'http://' . $_SERVER['SERVER_NAME'] . '/assets/includes/magpierss/rss_fetch.inc';
$url = 'http://jobfunctions.bnet.com/xml/RSS-1709.xml' ;
$rss = fetch_rss($url);
echo '<h6></h6><h5>Site: ' , $rss->channel['title'], ' </h5>';
if ( $rss and!$rss->ERROR) {
foreach ($rss->items as $item ) {
echo '<p><a href="' . $item[link] . '">' . $item[title] . ' </a></p>';
echo '<p>' . $item[description] . '</p>' ;
echo '<p>' . $item[pubdate] . '</p><h6></h6>';
}
} else {
echo 'RSS Error: ' . $rss->ERROR . '<h6></h6>' ;
}
?>
4:50 pm on Jun 16, 2005 (gmt 0)

10+ Year Member



It is the foreach loop that goes through all the articles. If you just want the first, give this a try:
<?php
require_once 'http://' . $_SERVER['SERVER_NAME'] . '/assets/includes/magpierss/rss_fetch.inc';
$url = 'http://jobfunctions.bnet.com/xml/RSS-1709.xml' ;
$rss = fetch_rss($url);
echo '<h6></h6><h5>Site: ' , $rss->channel['title'], ' </h5>';
if ( $rss and!$rss->ERROR) {
$item = $rss->items[0];
echo '<p><a href="' . $item[link] . '">' . $item[title] . ' </a></p>';
echo '<p>' . $item[description] . '</p>' ;
echo '<p>' . $item[pubdate] . '</p><h6></h6>';
} else {
echo 'RSS Error: ' . $rss->ERROR . '<h6></h6>' ;
}
?>

note: you replace the foreach line, and have to remove one of the } before the "else"
6:43 pm on Jun 19, 2005 (gmt 0)

10+ Year Member



works great! thanks!
 

Featured Threads

Hot Threads This Week

Hot Threads This Month