[pmwiki-users] pagelist sorting
Hans
design5 at softflow.co.uk
Tue Mar 6 04:50:59 CST 2007
Tuesday, March 6, 2007, 10:34:48 AM, Hans wrote:
> Here is a custom PagelistSortOrder function for sorting pages by numerical
> pagetextvar data:
Perhaps the function should better be called IntegerDataCompare:
Add to local config (or recipe script:
# sorting pages by numerical pagetext var data
function IntegerDataCompare($x, $y, $var) {
# get integer value of the page text variable
$xval = intval(PageTextVar($x, $var));
$yval = intval(PageTextVar($y, $var));
# compare integer values
if($xval > $yval) $c = 1;
elseif($xval < $yval) $c = -1;
else $c = 0;
return $c;
}
# defining order=books to sort integers numerical by pagetextvar $:Books
$PageListSortCmp['books'] = 'IntegerDataCompare($x, $y, "Books")';
Then use in your pagelist directive with order=books (numerical sort
smallest number first) or order=-books (largest number first)
For other integer page text variables just create another array item for
$PageListSortCmp, as done above with "Books"
Hans
More information about the pmwiki-users
mailing list