Dietrich George
Dietrich George

Reputation: 114

SimplePie Multiple Feeds Random Order

I am new to SimplePie and was looking through the API and couldn't find what I needed. I need to use Simple Pie to get random articles from multiple feeds. I'll better explain my question:

Here's how SimplePie gives me the feed now (in chronological order):

Here is how I need it (in random order):

and so forth..

As far as I know, I would have to make a separate SimplePie feed everytime just to pull one unique article. I want Simple Pie to be able to do this with one call, but just rearranging them in before it sends it back. So kind of like a custom resort.

Please help :)

Upvotes: 1

Views: 582

Answers (1)

Teno
Teno

Reputation: 2632

I had the same question here: Custom Sort Order with SimplePie

You need to extend the class.

class SimplePie_Random_Sort extends SimplePie
{
    public static function sort_items($a, $b)
    {
        return rand(-1, 1);
    }
}

Upvotes: 3

Related Questions