Last active
May 8, 2020 16:28
-
-
Save yehchge/63e7a4a1581b3b3d3f0241adc5eada33 to your computer and use it in GitHub Desktop.
pagebar
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
function sMakePageBar($iAllItems,$iPageItems,$iPg=0,$sUrl){ | |
$iPages = 0; | |
$sPageBar = ''; | |
$current = 0; | |
$PHP_SELF = $_SERVER['PHP_SELF']; | |
if ($iPageItems) $iPages = (INT)($iAllItems/$iPageItems); | |
if($iPageItems AND $iAllItems%$iPageItems==0) $iPages--; | |
if($iPages > 0) { | |
// ===== Make PageBar ===== | |
$iPrevPage = $iPg-1; | |
if($iPrevPage<0) $iPrevPage=0; | |
$iNextPage = $iPg+1; | |
if($iNextPage>$iPages) $iNextPage=$iPages; | |
if($iPg>0){ | |
$sPageBar.="<li class='prev '><a href='$PHP_SELF?$sUrl&items=$iPageItems&page=$iPrevPage'><i class='icon-double-angle-left'></i></a></li>"; | |
}else{ | |
$sPageBar.="<li class='prev disabled'><a href='$PHP_SELF?$sUrl&items=$iPageItems&page=$iPrevPage'><i class='icon-double-angle-left'></i></a></li>"; | |
} | |
$iTp = 9; | |
$iPi = 0; | |
$iPage = $iPg; | |
$iHpages = $iPages; | |
if($iPages>$iTp) { | |
$htp = (INT)($iTp/2); | |
$iPi = $iPage-$htp; | |
if($iPi<0) $iPi=0; | |
$iHpages = $iPi+$iTp; | |
if($iHpages >$iPages ) { | |
$iHpages = $iPages; | |
$iPi = $iHpages-$iTp; | |
} | |
} | |
for($i=$iPi;$i<=$iHpages;$i++) { | |
if($iPage!=$i){ | |
$sPageBar .= "<li><a href='$PHP_SELF?$sUrl&items=$iPageItems&page=$i'>"; | |
$sPageBar .= ($i+1); | |
$sPageBar .= "</a></li>"; | |
} else { | |
$sPageBar .= "<li class='active'><a>".($i+1)."</a></li>"; | |
$current = $i+1; | |
} | |
} | |
if($iPg < $iPages){ | |
$sPageBar .= "<li class='next'><a href='$PHP_SELF?$sUrl&items=$iPageItems&page=$iNextPage' ><i class='icon-double-angle-right'></i></a></li>"; | |
} | |
$sPageBar .= '<li><a>Page '.($current).' of '.($iPages+1).'</a></li>'; | |
// ===== Make PageBar ===== | |
} | |
if($sPageBar) { | |
$sPageBar = "<ul>".$sPageBar."</ul>"; | |
} | |
return $sPageBar; | |
} | |
?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment