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:
$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/'); $num_items=10; $rss=fetch_rss("" ); $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?
posted by Dreama to Computers & Internet (4 answers total)
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.
posted by Dreama at 12:33 PM on February 2, 2007

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

should be

foreach ($items as $item) {

posted by cillit bang at 12:40 PM on February 2, 2007



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

posted by Dreama at 1:51 PM on February 2, 2007

« Older Real life versions of fictional software   |   What's this directshow software doing? Newer »
This thread is closed to new comments.