Created
May 25, 2013 00:43
-
-
Save fernandosavio/5647446 to your computer and use it in GitHub Desktop.
Script que retorna um range do números das páginas baseado nos parâmetros recebidos.
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 pagination ($index, $teto, $amplitude = 7, $piso = 1){ | |
$padding = intval($amplitude/2); | |
$amplitude = min(array($amplitude,$teto)); | |
$left = $padding; | |
$right = $amplitude - $left - 1; | |
if($index - $padding < $piso){ | |
$left = $index - $piso; | |
$right = $amplitude - ($left + 1); | |
} | |
if($index + $padding > $teto){ | |
$right = $teto - $index; | |
$left = $amplitude - ($right + 1); | |
} | |
return range($index - $left, $index + $right); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment