티스토리 뷰
First Previous 1 2 3 ... 22 23 24 25 26 [27] 28 29 30 31 32 ... 48 49 50 Next Last
$total_pages = 25; // 전체 페이지 갯수
$count_out = 3; // 처음과 끝에 표시되는 번호 갯수
$count_in = 5; // 현재 페이지 기준으로 표시되는 번호 갯수
$current_page = ($_GET['p'] ) ? $_GET['p'] : 1; // 현재 페이지 갯수
// 처음 표시되는 갯수
$n1 = 1;
$n2 = min($count_out, $total_pages);
// 마지막에 표시되는 갯수
$n7 = max(1,$total_pages - $count_out + 1);
$n8 = $total_pages;
// 가운데일 경우 표시
$n4 = max( $n2 + 1, $current_page - $count_in );
$n5 = min( $n7 - 1, $current_page + $count_in );
$use_middle = ($n5 -->= $n4);
$n3 = (int) ( ($n2 + $n4) / 2 );
$use_n3 = ( $use_middle && (($n4 - $n2) > 1 ) );
$n6 = (int) ( ($n5 + $n7) / 2 );
$use_n6 = ( $use_middle && ( ($n7 - $n5) > 1 ) );
$links = array();
for($i=$n1; $i <= $n2; $i++) {
$links[$i] = $i;
}
if ( $use_n3 ) {
$links[$n3] = '…';
}
for($i=$n4; $i <= $n5; $i++) {
$links[$i] = $i;
}
if ( $use_n6 ) {
$links[$n6] = '…';
}
for($i=$n7; $i <= $n8; $i++) {
$links[$i] = $i;
}
foreach ($links as $number => $content){
if ($number ==$current_page) {
echo " [" .$content . "] ";
} else {
if ( is_numeric($content) ) {
echo " [" .$content . "] ";
} else {
echo $content ;
}
}
}
'웹개발 > Php' 카테고리의 다른 글
| PHP 알려지지 않은 트릭 몇가지 (0) | 2011.06.30 |
|---|---|
| PHP 데코레이터 패턴 !!!! (0) | 2011.06.14 |
| Kohana3 - 연구 (0) | 2011.06.08 |
| csv 파일 저장, 읽기 (0) | 2011.03.24 |
| php 날짜 계산 strtotime 이용 (0) | 2011.02.18 |
댓글