CaRP Evolution Box
Web This Site

CaRP: Caching RSS Parser - Documentation


CaRP Interactive FAQ
Getting Started: Free Download | Purchase | Install
Reference: Functions | Plugins | Themes | Full Index
Etc.: Display Formatting | Example Code | Affiliates

Sort

See the Sort plugin in action
Sort is a plugin bundled with CaRP Evolution 4.0.8 and higher. It enables the sorting of feed items by any item field in either ascending or descending order. It can also shuffle items in a random order. Finally, it can be used with your own custom sorting function to provide complex sorting capabilities.
 
Installation:
To install Sort, put sort.php into the "plugins" folder inside the folder containing carp.php. (If no plugins folder exists, create one.)
 
Use:
To tell CaRP Evolution to use Sort, first, enter the following command into your webpage after "require_once '/path/to/carp.php';":
 
     CarpLoadPlugin('sort.php');

Then use use the functions and/or configuration settings listed below to select your desired sorting order.

Important Notes:  
Functions:
Your code may call the following functions from the Sort plugin after you have loaded it as described above:

 
Configuration:
The Sort plugin has the following settings, which are members of the array $sortcarpconf. In most cases, you'll use the functions listed above to control these settings:

Example Code:
To sort the entire feed alphabetically by title:

<?php
require_once '/YOUR/PATH/TO/carp/carp.php';
CarpLoadPlugin('sort.php');
CarpCacheShow('http://example.com/videos.rss');
?>


To display 3 items in random order:

<?php
require_once '/YOUR/PATH/TO/carp/carp.php';
CarpLoadPlugin('sort.php');
$sortcarpconf['function']='';
$sortcarpconf['max-items']=3;
CarpCacheShow('http://example.com/videos.rss');
?>


The following code sorts Slashdot's feed by the number of comments attached to each item and displays only the title link and the number of comments. Note that it is not necessary to call CarpMapField to display the comment count because this plugin automatically maps "slash:comments" (the sort field) to "sortslash:comments" (which you see specified in the "iorder" setting):

<?php
require_once '/YOUR/PATH/TO/carp/carp.php';
CarpLoadPlugin('sort.php');
SortCarpByOneElement('slash:comments','descending');
CarpConf('iorder','link,sortslash:comments');
function ShowCommentCount($initem,$fn,$ii,$in,$va,$rv) {
   global $carpconf;
   return 'Comments: '.($carpconf['rssparser']->GetFieldValue('sortslash:comments')).'<br />';
}
CarpRegisterCallback('','ShowCommentCount','handlefield','sortslash:comments');
CarpCacheShow('http://slashdot.org/index.rss');
?>