Subscribe: Comments on: PHP/MagpieRSS troubleshooting
http://ask.metafilter.com/56248/PHPMagpieRSS-troubleshooting/rss
Added By: Feedage Forager Feedage Grade B rated
Language: English
Tags:
array slice  array  feed  items array  items num  items  magpie  magpierss troubleshooting  magpierss  newest  num items  num  slice 
Rate this Feed
Rate this feedRate this feedRate this feedRate this feedRate this feed
Rate this feed 1 starRate this feed 2 starRate this feed 3 starRate this feed 4 starRate this feed 5 star

Comments (0)

Feed Details and Statistics Feed Statistics
Preview: Comments on: PHP/MagpieRSS troubleshooting

Comments on: PHP/MagpieRSS troubleshooting



Comments on Ask MetaFilter post PHP/MagpieRSS troubleshooting



Published: Fri, 02 Feb 2007 12:33:46 -0800

Last Build Date: Fri, 02 Feb 2007 12:33:46 -0800

 



Question: PHP/MagpieRSS troubleshooting

Fri, 02 Feb 2007 12:31:14 -0800

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:
$num_items = [number of items wanted];
$rss = fetch_rss($URL);
$items = array_slice($rss->items, 0, $num_items);

So I've plugged this into markup, and I'm calling the inclusion of the feed with this:
< ?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;
}
?>
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.

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?



By: Dreama

Fri, 02 Feb 2007 12:33:46 -0800

Bah, my markup got chewed up. Also, I cut and pasted the wrong thing. Where it says $num_items=10; above, it actually says $num_items=1; in my actual test page.



By: cillit bang

Fri, 02 Feb 2007 12:40:12 -0800

foreach ($rss->items as $item) {

should be

foreach ($items as $item) {

right?



By: scottreynen

Fri, 02 Feb 2007 13:50:45 -0800

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.



By: Dreama

Fri, 02 Feb 2007 13:51:11 -0800

Bingo!