- var_dump: documentation ( source)
- ceil: documentation ( source)
- max: documentation ( source)
<?php
/*
http://3v4l.org/DCTnA
*/
/*
< [1] 2 3 ... 22 23 >
< 1 [2] 3 ... 22 23 >
< 1 2 [3] 4 ... 22 23 >
< 1 2 3 [4] 5 ... 22 23 >
< 1 2 ... 4 [5] 6 ... 22 23 >
< 1 2 ... 5 [6] 7 ... 22 23 >
...
< 1 2 ... 18 [19] 20 ... 22 23 >
*/
$currentpageid = $nmstart = 3;
$nrtotal = 23;
$nrposts = 1;
$pages = '';
$ssPagingStartCount = 3;
$ssPagingCurrentCount = 3;
$ssPagingEndCount = 2;
$totalpages = ceil($nrtotal / $nrposts);
if ($totalpages > 1 ){
/*
for ($x = 0; $x < $totalpages; ++$x) {
$inc = $x * $nrposts;
$display = $x + 1;
if($inc != $nmstart) {
$pages .= "\n<a class=\"nl_page\" href='" . "nmstart=$inc'>".$display."</a>";
} else {
$pages .= "\n<span class=\"nl_page nl_page__currentpage\">".$display."</span>";
}
}
*/
if ( ($currentpageid >= 0) && ($currentpageid < $ssPagingStartCount) ) {
for ($x = 0; (($x <= max($ssPagingStartCount, ($currentpageid + (int)($ssPagingCurrentCount/2)))) && ($x < $totalpages)); ++$x) {
$inc = $x * $nrposts;
$display = $x + 1;
if ($inc != $nmstart) {
$pages .= "\n<a class=\"nl_page\" href='" . "nmstart=$inc'>".$display."</a>";
} else {
$pages .= "\n<span class=\"nl_page nl_page__currentpage\">".$display."</span>";
}
}
}
}
var_dump($pages);
?>