SimplePie多个Feed随机顺序 [英] SimplePie Multiple Feeds Random Order
问题描述
我是SimplePie的新手,正在查看API,找不到我需要的东西.我需要使用Simple Pie从多个提要中获取随机文章.我会更好地解释我的问题:
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:
这是SimplePie现在给我提要的方式(按时间顺序):
Here's how SimplePie gives me the feed now (in chronological order):
- 第1条(CNN)
- 第2条(CNN)
- 第3条(CNN)
- 第4条(CNN)
-
第5条(CNN)
- Article 1 (CNN)
- Article 2 (CNN)
- Article 3 (CNN)
- Article 4 (CNN)
Article 5 (CNN)
第1条(YAHOO)
第5条(YAHOO)
第1条(GOOGLE)
Article 1 (GOOGLE)
这是我的需要方式(随机排列):
Here is how I need it (in random order):
- 第3条(CNN)
- 第1条(GOOGLE)
- 第5条(YAHOO)
- 第3条(GOOGLE)
- 第2条(CNN)
- 第4条(YAHOO)
- 第1条(CNN)
- 第3条(GOOGLE)
- 第3条(YAHOO)
等等.
据我所知,我每次都必须制作一个单独的SimplePie feed,以获取一篇独特的文章.我希望Simple Pie可以通过一个呼叫完成此操作,但是只需在将其发送回之前重新排列它们即可.有点像自定义度假村.
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.
请帮助:)
推荐答案
I had the same question here: Custom Sort Order with SimplePie
您需要扩展该类.
class SimplePie_Random_Sort extends SimplePie
{
public static function sort_items($a, $b)
{
return rand(-1, 1);
}
}
这篇关于SimplePie多个Feed随机顺序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!