SimplePie 1.5 is now available!

SimplePie Documentation.  Learn how to use this thing.  It's way better than going to school.

You are here: Documentation » API Reference » SimplePie » sort_items()



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:


  • Available since SimplePie 1.0.



A reference to the first item to sort.


A reference to the second item to sort.


Sort items by number of characters in the title, shortest first

// 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();
<?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; ?>

See Also

reference/simplepie/sort_items.txt · Last modified: 2011/03/06 03:56 (external edit)