Jared
Jared

Reputation: 3

How to display multiple RSS feeds but only display the most recent post from each feed in simplepie

I am currently trying to display multiple feeds as a single feed using Simplepie. I have the feeds in an array and displaying fine:

    $feeds = array(
        'feed1',
        'feed2',
        'feed3'
    );

This displays:

    feed1
    feed1
    feed1
    feed1

    feed2 
    feed2
    feed2
    feed2

    feed3 
    feed3
    feed3
    feed3

My question is how do I loop through the array and only access the most recent post/article from each feed so that only the first post/article in each feed shows like:

    Feed1(most recent)
    Feed2(most recent)
    Feed3(most recent)

Probably the closet thing I have found to what I want to accomplish is this answer:

SimplePie Multiple Feeds Random Order

But I don't want it to be random. My feeling is that sort_items is the way to go with this but I need some direction.

Any help is appreciated.

Thank you for your time.

Jared

Upvotes: 0

Views: 309

Answers (1)

Revent
Revent

Reputation: 2109

They have a parameter for that.

$max_items_per_feed = 1;
$feed->set_item_limit($max_items_per_feed);

This sets how many items to pull from each feed. You can set it to 5, 27, or 1 in your case. You put this code above your $feed->init(); function call.

Upvotes: 1

Related Questions