[pmwiki-users] Numerical sort order

Petko Yotov 5ko at 5ko.fr
Thu Jul 20 10:38:48 CDT 2017

On 2017-07-18 21:36, Pete Lomax wrote:
> Hi there, first time poster here.
> I've got VoteCounter working, apart from the pagelist order, and I'm
> looking at CustomPagelistSortOrderFunctions - but I think the problem
> is that VoteWeightedSum is a pagevar, not a pagetextvar.
> Can the equivalent of IntegerDataCompare be done for VoteWeightedSum?

Yes, it can. Something like this:

   # sorting pages by numerical integer pagevar data
   function IntegerPVCompare($x, $y, $var) {
     # get integer value of the page text variable
     $xval = intval(PageVar($x, $var));
     $yval = intval(PageVar($y, $var));
     # compare integer values
     if($xval == $yval) return 0;
     return ($xval > $yval) ? 1 : -1;

   # order=votes to sort numerically by {$VoteWeightedSum}
   $PageListSortCmp['votes'] = 'IntegerPVCompare($x, $y, 

   # order=votecount to sort numerically by {$VoteCount}
   $PageListSortCmp['votecount'] = 'IntegerPVCompare($x, $y, 

Use order=-votecount to see those with most votes on top.


PmWeekly Blog  :  http://www.pmwiki.org/wiki/News
Change log     :  http://www.pmwiki.org/wiki/PmWiki/ChangeLog
Release notes  :  http://www.pmwiki.org/wiki/PmWiki/ReleaseNotes
If you upgrade :  http://www.pmwiki.org/wiki/PmWiki/Upgrades

More information about the pmwiki-users mailing list