[pmwiki-devel] how to access MatchCount from pagelist
Hans
design5 at softflow.co.uk
Thu Feb 12 19:24:38 CST 2009
Thursday, February 12, 2009, 9:01:09 PM, Patrick wrote:
> ...or, if I'm wrong and it's not really possible to get to the matchcount
> easily, you can propose modifications to FPLTemplate() for the core. :-)
okay, I can't get it to work unless there are some changes.
Here is a code proposal. It introduces a PV $PageListCount,
which works great in a pagelist template to show the total number of
items.
It also introduces a start= parameter, so we can tell pagelist
from which item to start a chunk. If start is negative, it counts
from the end.
If count= is given as well, it will begin at 'start' position for
'count' items.
If start is given and count is given as a range, it gets a bit tricky:
it will start at 'start' and show length of range items.
Here is the code, I include the preceding line and the following code
for the range, which has one change ($PageListCount, since $matches
may have been sliced already) :
## get the list of pages
$matches = array_values(MakePageList($pagename, $opt, 0));
global $FmtPV, $PageListCount;
$PageListCount = count($matches);
$FmtPV['$PageListCount'] = $PageListCount;
## extract page subset according to 'start=' parameter
if (@$opt['start']) {
if ($opt['start'] >= 0)
$matches = array_slice($matches, $opt['start']-1);
else
$matches = array_slice($matches, $PageListCount+$opt['start']);
}
## extract page subset according to 'count=' parameter
if (@$opt['count']) {
list($r0, $r1) = CalcRange($opt['count'], $PageListCount);
if ($r1 < $r0)
$matches = array_reverse(array_slice($matches, $r1-1, $r0-$r1+1));
else
$matches = array_slice($matches, $r0-1, $r1-$r0+1);
}
Hans
More information about the pmwiki-devel
mailing list