homepage Welcome to WebmasterWorld Guest from 54.145.209.80
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

    
Limiting number of headlines isn't working
magpie instructions don't seem to work.
revtim

5+ Year Member



 
Msg#: 3681891 posted 9:41 pm on Jun 23, 2008 (gmt 0)

I added RSS feed using your simple guide. So far so good. Only one small hitch. I am getting about 35 headlines and I want to limit it to more like 20. I checked magpie and got this instruction.

You want to display the 10 (or 3) most recent headlines, but the RSS feed
contains 15.

SOLUTION:

$num_items = 10;
$rss = fetch_rss($url);

$items = array_slice($rss->items, 0, $num_items);

DISCUSSION:

Rather then trying to limit the number of items Magpie parses, a much simpler,
and more flexible approach is to take a "slice" of the array of items. And
array_slice() is smart enough to do the right thing if the feed has less items
then $num_items.

See: [php.net...]

I located the $rss = fetch_rss($url); in the feed.php code and replaced it with the above code since it is duplicated and expanded in the replacement code.

I uploaded feed.php to my site and nothing changed. Even when i open mydomain/rssdemo/feed.php there are still all the headlines. (yes, i ctl/refreshed to make sure)

So, where did I go wrong. I noticed this same question was asked when the simple guide was first posted but no one responded.

Thanks

 

eelixduppy

WebmasterWorld Senior Member eelixduppy us a WebmasterWorld Top Contributor of All Time 5+ Year Member



 
Msg#: 3681891 posted 1:52 am on Jun 24, 2008 (gmt 0)

My guess is you still have it as the following:

foreach($rss-items as $item) { etc...

You should be echoing the results as follows now with your new code:

foreach($items as $item) {
echo '<pre>'; print_r($item); echo '</pre>';
}

try that and see what that gets you.

revtim

5+ Year Member



 
Msg#: 3681891 posted 11:39 am on Jun 24, 2008 (gmt 0)

Actually, if you check the guide, the code foreach($rss-items as $item) does not appear and it doesn't appear in my code either as all I did was change the RSS feed URL.
[webmasterworld.com ]

I will gladly add it if you tell me where in feed.php I should insert it. Thanks for the interest.

revtim

5+ Year Member



 
Msg#: 3681891 posted 12:53 pm on Jun 24, 2008 (gmt 0)

PS.... I copy/pasted that snippet below the code in my original post and it really screwed things up (added a bunch of the headlines in plain text above my existing list and spread my page out something awful) so obviously, I need to put it someplace else.
Thanks

eelixduppy

WebmasterWorld Senior Member eelixduppy us a WebmasterWorld Top Contributor of All Time 5+ Year Member



 
Msg#: 3681891 posted 2:03 pm on Jun 24, 2008 (gmt 0)

Sorry, I didn't actually look at the guide. I was giving you code so that you can see if the number of results was accurate (10). From the guide, it looks like you have to change the following code:

$tpl->assign("items",$rss->items);

To this:

$tpl->assign("items",[b]$items[/b]);

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