|
Cookbook /
CustomPagelistSortOrderFunctionsSummary: Custom functions for creating custom page sort orders with pagelists
Version: 2007-03-06
Prerequisites: pmwiki 2.2.0 beta
Status:
Maintainer:
DescriptionCustom functions for creating custom page sort orders with pagelists. Sorting pages by integer pagetextvar data:Here is a custom PagelistSortOrder function for sorting pages by numerical PageTextVariable data. Add to local config (or recipe script): # sorting pages by numerical integer pagetextvar 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" Sorting pages by integer numbers of pagename (Title)Add to local config (or recipe script): function IntegerNameCompare($x, $y) {
# get integer value of the page name or title
$xval = intval(PageVar($x, '$Title'));
$yval = intval(PageVar($y, '$Title'));
# compare integer values
if($xval > $yval) $c = 1;
elseif($xval < $yval) $c = -1;
else $c = 0;
return $c;
}
$PageListSortCmp['intname'] = 'IntegerNameCompare($x, $y)';
Then use in your PageList directive with order=intname (numerical sort smallest number first) or order=-intname (largest number first). To exclude other page names from the list and use only pagenames starting with a digit use in the pagelist directive: name=[0-9]* Example:
(:pagelist group={$Group} name=[0-9]* order=intname fmt=#title :)NotesWouldn't it be easier to just use strnatcasecmp()? http://us3.php.net/manual/en/function.strnatcasecmp.php
It can handle combinations of integers and text, so that Page11 < Page100, etc. Ben Stallings March 15, 2007, at 01:08 PM Release Notes
CommentsSee AlsoContributors |