PHP/MagpieRSS troubleshooting
February 2, 2007 12:31 PM Subscribe
How to customize MagpieRSS output when array_slice seems to be broken?
I've got MagpieRSS running, and working, in order to integrate the RSS feeds from 9 different sources into the front page of my domain. But I want only to have a link to the latest item in each of those sources (only the headline link to the newest blog post, newest recipe, newest photo on Flickr, etc.) and Magpie is fetching every item available in the feed and spitting it out.
Per the Magpie FAQ, the answer to this is:
Anyone with the php chops to tell me what it is I'm missing that can solve this problem? All I want in the end is just that one link, how can I stop it from giving more than I need?
I've got MagpieRSS running, and working, in order to integrate the RSS feeds from 9 different sources into the front page of my domain. But I want only to have a link to the latest item in each of those sources (only the headline link to the newest blog post, newest recipe, newest photo on Flickr, etc.) and Magpie is fetching every item available in the feed and spitting it out.
Per the Magpie FAQ, the answer to this is:
So I've plugged this into markup, and I'm calling the inclusion of the feed with this:$num_items = [number of items wanted]; $rss = fetch_rss($URL); $items = array_slice($rss->items, 0, $num_items);
but this isn't working. (My test page is here.) I'm still getting the entire list of available items in the feed. (I'd get 10, I guess, which is the Magpie default, but there aren't that many items in the feed yet.) From some Googling, I see that array_slice doesn't always seem to work but I haven't been able to find a workable solution.< ?php require_once('magpierss/rss_fetch.inc'); $num_items=10; $rss=fetch_rss(" http://mefiswap.bluesilver.org/feed/" ); $items=array_slice($rss->items, 0, $num_items); echo ; foreach ($rss->items as $item) { $href = $item['link']; $title = $item['title']; $date = $item['date']; echo "$title
"; if($desc) echo $desc; } ?>>
Anyone with the php chops to tell me what it is I'm missing that can solve this problem? All I want in the end is just that one link, how can I stop it from giving more than I need?
Best answer: foreach ($rss->items as $item) {
should be
foreach ($items as $item) {
right?
posted by cillit bang at 12:40 PM on February 2, 2007
should be
foreach ($items as $item) {
right?
posted by cillit bang at 12:40 PM on February 2, 2007
right?
Right.
Some general advise: next time you think a function isn't working (e.g. array_slice), print_r() its output. You'll either learn that the problem is further down the line, or you'll get a better idea of exactly how it's failing.
posted by scottreynen at 1:50 PM on February 2, 2007
Right.
Some general advise: next time you think a function isn't working (e.g. array_slice), print_r() its output. You'll either learn that the problem is further down the line, or you'll get a better idea of exactly how it's failing.
posted by scottreynen at 1:50 PM on February 2, 2007
This thread is closed to new comments.
posted by Dreama at 12:33 PM on February 2, 2007