게시판 페이징 질문입니다.

게시판 페이징 질문입니다.

QA

게시판 페이징 질문입니다.

본문

게시판 페이징 질문입니다.

 

처음 이전 버튼,다음버튼이랑 맨끝 버튼 그냥 다 보이게 하고 싶은데 어떻게 해야 할까요?

 

  $str = '';
    if ($cur_page > 1) {
        $str .= '<a href="'.$url.'1'.$add.'" class="pg_page pg_start">처음</a>'.PHP_EOL;
    }

    $start_page = ( ( (int)( ($cur_page - 1 ) / $write_pages ) ) * $write_pages ) + 1;
    $end_page = $start_page + $write_pages - 1;

    if ($end_page >= $total_page) $end_page = $total_page;

    if ($start_page > 1) $str .= '<a href="'.$url.($start_page-1).$add.'" class="pg_page pg_prev">이전</a>'.PHP_EOL;

    if ($total_page > 1) {
        for ($k=$start_page;$k<=$end_page;$k++) {
            if ($cur_page != $k)
                $str .= '<a href="'.$url.$k.$add.'" class="pg_page">'.$k.'<span class="sound_only">페이지</span></a>'.PHP_EOL;
            else
                $str .= '<span class="sound_only">열린</span><strong class="pg_current">'.$k.'</strong><span class="sound_only">페이지</span>'.PHP_EOL;
        }
    }

    if ($total_page > $end_page) $str .= '<a href="'.$url.($end_page+1).$add.'" class="pg_page pg_next">다음</a>'.PHP_EOL;

    if ($cur_page < $total_page) {
        $str .= '<a href="'.$url.$total_page.$add.'" class="pg_page pg_end">맨끝</a>'.PHP_EOL;
    }

    if ($str)
        return "<nav class=\"pg_wrap\"><span class=\"pg\">{$str}</span></nav>";
    else
        return "";
}

이 질문에 댓글 쓰기 :

답변 1

처음, 이전, 다음, 맨끝버튼 아래처럼 하시면 돼요.


$str = '';
 //if ($cur_page > 1) {
  $str .= '<a href="'.$url.'1'.$add.'" class="pg_page pg_start">처음</a>'.PHP_EOL;
 //}
$start_page = ( ( (int)( ($cur_page - 1 ) / $write_pages ) ) * $write_pages ) + 1;
 $end_page = $start_page + $write_pages - 1;
if ($end_page >= $total_page) $end_page = $total_page;
//if ($start_page > 1) $str .= '<a href="'.$url.($start_page-1).$add.'" class="pg_page pg_prev">이전</a>'.PHP_EOL;
$str .= '<a href="'.$url.($start_page-1).$add.'" class="pg_page pg_prev">이전</a>'.PHP_EOL;
if ($total_page > 1) {
  for ($k=$start_page;$k<=$end_page;$k++) {
   if ($cur_page != $k)
    $str .= '<a href="'.$url.$k.$add.'" class="pg_page">'.$k.'<span class="sound_only">페이지</span></a>'.PHP_EOL;
   else
    $str .= '<span class="sound_only">열린</span><strong class="pg_current">'.$k.'</strong><span class="sound_only">페이지</span>'.PHP_EOL;
  }
 }
//if ($total_page > $end_page) $str .= '<a href="'.$url.($end_page+1).$add.'" class="pg_page pg_next">다음</a>'.PHP_EOL;
$str .= '<a href="'.$url.($end_page+1).$add.'" class="pg_page pg_next">다음</a>'.PHP_EOL;

//if ($cur_page < $total_page) {
  $str .= '<a href="'.$url.$total_page.$add.'" class="pg_page pg_end">맨끝</a>'.PHP_EOL;
//}
if ($str)
  return "<nav class=\"pg_wrap\"><span class=\"pg\">{$str}</span></nav>";
 else
  return "";
 }

수정했습니다.


$str = '';
    if ($cur_page > 1) {
        $str .= '<a href="'.$url.'1'.$add.'" class="pg_page pg_start">처음</a>'.PHP_EOL;
     }else{
		$str .= '<a href="javascript:;" class="pg_page pg_start">처음</a>'.PHP_EOL;
	 }

    $start_page = ( ( (int)( ($cur_page - 1 ) / $write_pages ) ) * $write_pages ) + 1;
     $end_page = $start_page + $write_pages - 1;

    if ($end_page >= $total_page) $end_page = $total_page;

    if ($start_page > 1){
		$str .= '<a href="'.$url.($start_page-1).$add.'" class="pg_page pg_prev">이전</a>'.PHP_EOL;
	}else{
		$str .= '<a href="javascript:;" class="pg_page pg_prev">이전</a>'.PHP_EOL;
	}
    if ($total_page > 1) {
         for ($k=$start_page;$k<=$end_page;$k++) {
             if ($cur_page != $k)
                 $str .= '<a href="'.$url.$k.$add.'" class="pg_page">'.$k.'<span class="sound_only">페이지</span></a>'.PHP_EOL;
             else
                 $str .= '<span class="sound_only">열린</span><strong class="pg_current">'.$k.'</strong><span class="sound_only">페이지</span>'.PHP_EOL;
         }
     }

    if ($total_page > $end_page){
		$str .= '<a href="'.$url.($end_page+1).$add.'" class="pg_page pg_next">다음</a>'.PHP_EOL;
	}else{
		$str .= '<a href="javascript:;" class="pg_page pg_next">다음</a>'.PHP_EOL;
	}
    if ($cur_page < $total_page) {
         $str .= '<a href="'.$url.$total_page.$add.'" class="pg_page pg_end">맨끝</a>'.PHP_EOL;
	}else{
		$str .= '<a href="javascript:;" class="pg_page pg_end">맨끝</a>'.PHP_EOL;
	}

    if ($str)
         return "<nav class=\"pg_wrap\"><span class=\"pg\">{$str}</span></nav>";
     else
         return "";
 }

$cur_page 이게 현재페이지입니다.


$str .= '<a href="'.$url.($start_page-1).$add.'" class="pg_page pg_prev">이전</a>'.PHP_EOL;
//이전페이지 아래와 같이 변경.
$str .= '<a href="'.$url.($cur_page-1).$add.'" class="pg_page pg_prev">이전</a>'.PHP_EOL;


$str .= '<a href="'.$url.($end_page+1).$add.'" class="pg_page pg_next">다음</a>'.PHP_EOL;
//다음페이지 아래와 같이 변경.
$str .= '<a href="'.$url.($cur_page+1).$add.'" class="pg_page pg_next">다음</a>'.PHP_EOL;

답변을 작성하시기 전에 로그인 해주세요.
전체 115
QA 내용 검색

회원로그인

(주)에스아이알소프트 / 대표:홍석명 / (06211) 서울특별시 강남구 역삼동 707-34 한신인터밸리24 서관 1404호 / E-Mail: admin@sir.kr
사업자등록번호: 217-81-36347 / 통신판매업신고번호:2014-서울강남-02098호 / 개인정보보호책임자:김민섭(minsup@sir.kr)
© SIRSOFT