댓글 페이징 달기.
그누보드의 경우
댓글이 무한정으로 달릴경우
레이아웃이 하단으로 무한정 길어집니다.
레이아웃이나, 길어지는게 보기 좋지 않은분들을 위한 댓글 페이징 기능입니다.
코드하단에 아래 스크립트 추가.
[code]
$(function(){
paging();
paging_nation();
});
var view_comment = 5; // 페이지당 보여지는 댓글의 개수
function paging_nation()
{
$('.pagenation').on('click', function(e){
var Idx = $(this).index()+1;
var count = $('.a_comment').length;
var $a_comment = $('.a_comment');
var la_page = Idx * view_comment;
var fr_page = Idx * view_comment - view_comment;
$a_comment.slice(0).hide();
$a_comment.slice(fr_page, la_page).show();
console.log(fr_page, la_page);
$('.pagenation').removeClass('active');
$(this).addClass('active');
});
}
function paging()
{
var count = $('.a_comment').length;
var $a_comment = $('.a_comment');
$a_comment.slice(view_comment).hide();
var paging = '';
if(count>view_comment){
var totalpage = Math.floor(count/view_comment)+1;
for(var i=1;i<=totalpage;i++){
if(i==1)var active = "active";else var active='';
//paging += '<a href="javascript:;" class="pagenation" onclick="call_paging('+i+')">'+i+'</a>';
paging += '<a href="javascript:;" class="pagenation '+active+'">'+i+'</a>';
}
$('.paging').html(paging);
}
paging_nation();
}
[/code]
[code]
<article id="c_<?php echo $comment_id ?>" <?php if ($cmt_depth) { ?>style="margin-left:<?php echo $cmt_depth ?>px;border-top-color:#e0e0e0"<?php } ?>>
[/code]
부분을 찾아
[code]
<article class="a_comment" id="c_<?php echo $comment_id ?>" <?php if ($cmt_depth) { ?>style="margin-left:<?php echo $cmt_depth ?>px;border-top-color:#e0e0e0"<?php } ?>>
[/code]
아래와 같이 클래스명을 추가함.
[code]
</article>
<?php } ?>
<?php if ($i == 0) { //댓글이 없다면 ?><p id="bo_vc_empty">등록된 댓글이 없습니다.</p><?php } ?>
</section>
[/code]
부분을 찾아
[code]
</article>
<?php } ?>
<?php if ($i == 0) { //댓글이 없다면 ?><p id="bo_vc_empty">등록된 댓글이 없습니다.</p><?php } ?>
<div style="text-align: center">
<div class="paging"></div>
</div>
</section>
[/code]
아래와 같이 변경.
style.css
[code]
/*페이징 */
.paging {
display: inline-block;text-align: center
}
.paging a {
color: black;
float: left;
padding: 8px 16px;
text-decoration: none;
transition: background-color .3s;
border: 1px solid #ddd;
}
.paging a.active {
background-color: #253dbe;
color: white;
border: 1px solid #4CAF50;
}
.paging a:hover:not(.active) {background-color: #253dbe;}
[/code]
아래와 같이 추가.
자세한건 스샷과 링크의 페이지에서 확인해주세요.
포함된 파일은 그누보드 베이직 기준입니다.
댓글 11개
제가 적용해보니 페이징이 잘 됩니다.
다만, 회원으로 로그인해서 볼때는 페이징이 되는데, 비회원일때는 페이징이 안된 상태로 노출됩니다.
비회원일때도 페이징이 노출되도록 하는 방법은 없을까요?
댓글쓰기 권한을 1로 주면 페이징이 잘 됩니다.
하지만, 댓글쓰기 권한을 2로 주면 페이징이 되지 않고, 전체 댓글이 한번에 다 보입니다.
<?php if(!$is_member){?>
$('#bo_vc_w').remove();
<?php } ?>
추가하시면 됩니다.
문제 없이 제대로 작동 되어서 좋아요
감사합니다. ^^
게시판 목록
그누보드5 팁자료실
| 번호 | 제목 | 글쓴이 | 날짜 | 조회 |
|---|---|---|---|---|
| 공지 | 3년 전 | 4402 | ||
| 2664 |
선택과집중
|
4개월 전 | 571 | |
| 2663 |
|
4개월 전 | 619 | |
| 2662 |
|
4개월 전 | 574 | |
| 2661 |
선택과집중
|
4개월 전 | 508 | |
| 2660 | 4개월 전 | 588 | ||
| 2659 |
Modify
|
4개월 전 | 653 | |
| 2658 |
선택과집중
|
4개월 전 | 415 | |
| 2657 | 4개월 전 | 452 | ||
| 2656 |
|
4개월 전 | 964 | |
| 2655 |
선택과집중
|
4개월 전 | 548 | |
| 2654 | 4개월 전 | 403 | ||
| 2653 |
선택과집중
|
5개월 전 | 585 | |
| 2652 | 5개월 전 | 394 | ||
| 2651 | 5개월 전 | 446 | ||
| 2650 |
선택과집중
|
5개월 전 | 327 | |
| 2649 |
선택과집중
|
5개월 전 | 423 | |
| 2648 | 5개월 전 | 441 | ||
| 2647 |
welcome
|
5개월 전 | 545 | |
| 2646 |
디지털홍익인간
|
5개월 전 | 453 | |
| 2645 | 5개월 전 | 466 | ||
| 2644 |
선택과집중
|
5개월 전 | 512 | |
| 2643 | 5개월 전 | 456 | ||
| 2642 | 5개월 전 | 372 | ||
| 2641 | 5개월 전 | 358 | ||
| 2640 | 5개월 전 | 394 | ||
| 2639 | 5개월 전 | 1358 | ||
| 2638 |
|
5개월 전 | 510 | |
| 2637 |
세르반데스
|
5개월 전 | 398 | |
| 2636 |
선택과집중
|
5개월 전 | 568 | |
| 2635 |
선택과집중
|
6개월 전 | 682 |
댓글 작성
댓글을 작성하시려면 로그인이 필요합니다.
로그인하기