使用SimplePie的自定义排序顺序 [英] Custom Sort Order with SimplePie

查看:167
本文介绍了使用SimplePie的自定义排序顺序的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

使用SimplePie,如何按随机顺序和标题(字母顺序)对项目进行排序?根据此页面( http://simplepie.org/wiki/tutorial/sorting_by_custom_criteria_instead_of_date ),文档说扩展类并编写您自己的方法.但是如果没有更多示例,我似乎无法自己编写代码.

Using SimplePie, how can I sort items by random order and title (alphabetic)? According to this page (http://simplepie.org/wiki/tutorial/sorting_by_custom_criteria_instead_of_date), the documentation says to extend the class and write your own method. But without some more examples, I don't seem to be able to code it by myself.

目前,我将所有提要项放入数组并进行排序.但是,SimplePie的默认排序顺序是按日期.因此,如果某些url中有较新的项目,比如说其中有20项是新的,并且如果我总共仅获取20项,那么尽管我想以随机顺序显示这些项目,但输出却被来自Feed url有限来源的项目所占用每个都几个.

Currently I take all the feed items and put them into arrays and sort them. However, the default sort order of SimplePie is by date. Thus, if some urls have newer items let's say 20 of them are new and if I fetch only 20 items overall, then the output is occupied with the items from the limited source of feed urls although I want to show items in random order picking up a few from each.

我希望通过扩展类方法获得更多可行的示例.

I'm hoping some more working examples with the extended class method.

推荐答案

实际上,这确实很简单.哈哈

Actually it was really simple. haha

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

这篇关于使用SimplePie的自定义排序顺序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆