You are here: Documentation » API Reference » SimplePie » sort_items()
Table of Contents
sort_items()
Description
class SimplePie { sort_items ( mixed $a, mixed $b) }
This method is used exclusively as the user-defined function for PHP's usort() function. This is used for sorting items by a certain criteria, namely by date. If you would prefer to change the sorting criteria, you can simply extend the SimplePie class and override this method. You should never need to call this function directly.
Learn more about extending classes in PHP:
Availability
- Available since SimplePie 1.0.
Parameters
a
A reference to the first item to sort.
b
A reference to the second item to sort.
Examples
Sort items by number of characters in the title, shortest first
<?php require_once('../simplepie.inc'); // Create a new class that extends an existing class class SimplePie_Custom_Sort extends SimplePie { function sort_items($a, $b) { return strlen($a->get_title()) >= strlen($b->get_title()); } } // Let's do our standard SimplePie thing. $feed = new SimplePie_Custom_Sort(); $feed->set_feed_url('http://simplepie.org/blog/feed/'); $feed->init(); $feed->handle_content_type(); ?> <html> <body> <?php foreach ($feed->get_items(0,5) as $item): ?> <h4><a href="<?php echo $item->get_permalink()?>"><?php echo $item->get_title()?></a></h4> <p><small><?php echo $item->get_date('j F Y, g:i a')?></small></p> <p><?php echo $item->get_description()?></p> <hr /> <?php endforeach; ?> </body> </html>
See Also
reference/simplepie/sort_items.txt · Last modified: 2011/03/06 03:56 (external edit)