homepage Welcome to WebmasterWorld Guest from 54.145.183.190
register, free tools, login, search, pro membership, help, library, announcements, recent posts, open posts,
Become a Pro Member
Home / Forums Index / Code, Content, and Presentation / RSS, ATOM, and Related Technologies
Forum Library, Charter, Moderators: bill & werty

RSS, ATOM, and Related Technologies Forum

    
Posting only the first news articles as opposed to all of them.
rss php for each but for first?
cuce

10+ Year Member



 
Msg#: 276 posted 5:10 pm on Jun 15, 2005 (gmt 0)

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>' ;
}
?>

 

ChadSEO

5+ Year Member



 
Msg#: 276 posted 4:50 pm on Jun 16, 2005 (gmt 0)

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"

cuce

10+ Year Member



 
Msg#: 276 posted 6:43 pm on Jun 19, 2005 (gmt 0)

works great! thanks!

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.
Home ¦ Free Tools ¦ Terms of Service ¦ Privacy Policy ¦ Report Problem ¦ About ¦ Library ¦ Newsletter
WebmasterWorld is a Developer Shed Community owned by Jim Boykin.
© Webmaster World 1996-2014 all rights reserved