What set_item_limit exactly does in Simplepie?

488 Views Asked by At

i want to ask something specific. I have read the SimplePie manual but i am still confused. I am trying to mix items from different feeds but because i am passing the feeds urls through a random function to the SimplePie object everytime a feed is grabbed and parsed always its first item is presented by the Simplepie and as a result i have many times the same item of the same feed. I am using set_item_limit in order to present one item per feed.

So what i want to ask? Set_item_limit if i understood well, allows the user to loop through all the items of the feed but shows only the number the user indicates in the function?

If i am right, can i use set_item_limit(1) in order to show one article per feed but every time a different item and not the newest one??

1

There are 1 best solutions below

0
On

set_item_limit() is define how many feeds will be available for show.

    function fetch_feed($urls, $limit = 3) {
        require_once('lib/simplepie/simplepie.inc');

        $feed = new SimplePie();
        $feed->set_feed_url($urls);
        $feed->set_item_limit($limit);
        $feed->enable_cache(true);
        $feed->set_cache_duration(100);
        $feed->init();
        $feed->handle_content_type();   

        return $feed;
    }

$urls = array('feed_link_1', 'feed_link_2', 'feed_link_3');

$feed = fetch_feed($url, $limit = 5);

foreach($feed as $item){
   // do stuff with the item. This is the single feed item.
}

Here is a function i use for fetching feeds. You can see the use of set_item_limit(); function. Thanks!