[pmwiki-users] pagelist order

Hans design5 at softflow.co.uk
Thu Mar 20 18:39:45 CDT 2008

Thursday, March 20, 2008, 10:31:40 PM, Sameer Kumar wrote:

> I saw the page on custom sort orders
> <http://www.pmwiki.org/wiki/PmWiki/CustomPagelistSortOrder>  and tried
> to make sense of it. But being PHP-ignorant, I got thoroughly confused!
> Also, the fact that the page focuses on using the "Data-*" group didn't
> help...
> Would you be able to suggest some references where I can learn more
> about it?

try this: add to config:

$PageListSortCmp['shortyear'] = 'ShortYear($x, $y)';

function ShortYear($x, $y) {
        $projx = PageVar($x, '$Name');
        $projy = PageVar($y, '$Name');
        $yearx = substr($projx,0,2);
        $numx = substr($projx,2);
        $yeary = substr($projy,0,2);
        $numy = substr($projy,2);
        if ($yearx>=50) $px = '19'.$yearx.','.$numx;
        else $px = '20'.$yearx.','.$numx;
        if ($yeary>=50) $py = '19'.$yeary.','.$numy;
        else $py = '20'.$yeary.','.$numy;
        $c = strcmp($px, $py);
        return $c;

then use as in this example:

(:pagelist group=Projects list=normal fmt=-shortyear:)

which should give you a list of project pages with the latest top.
fmt=shortyear will show the oldest first.

The function divides the pagename into two parts:
a two digit year part (first two digits), and a numerical part, which
could be any length. If the year part is larger or equal 50 the year
part will get 19 in front 9for last century), otherwise 20 (for this
century). The numeric part gets added as decimal fraction digits.
Then values will be compared for the sorting.

I don't know what this does for pagenames which do not consist of
digits only, so better use with caution, or exclude other pagenames
in the pagelist directive.


More information about the pmwiki-users mailing list