댓글 최신순 정렬 및 페이징 문의드립니다.
본문
현재 댓글영역을 보면 댓글 등록순 으로 출력되며 그 밑에 textarea 영역이 표시되고 페이징이 안 되서 댓글 달려면 밑으로 쭉 내려야 하는 상황인데요..
댓글을 등록순이 아닌 최신순으로 출력되게 하고 10개 이상 달리면 페이징처리 되게끔 하고 싶습니다만.
게시판 설정에 "답변달기"에서 나중에 쓴 답변 위로달기 설정해도 설정이 안 되네요.
(댓글이 아닌 답변이라서 그런가요?)
어디를 어떻게 고처야 할까요?
팁 혹은 예제라도 부탁드립니다!
view_comment_skin.php 코드입니다!
[code]
<?php
if (!defined('_GNUBOARD_')) exit; // 개별 페이지 접근 불가
// 변수 초기값
$boset['na_shingo'] = isset($boset['na_shingo']) ? $boset['na_shingo'] : '';
// 페이징 댓글 사용유무
$is_paging = (isset($boset['na_crows']) && $boset['na_crows']) ? true : false;
// 댓글 추천 비추천 설정
$is_cgood = (isset($boset['na_cgood']) && $boset['na_cgood']) ? true : false;
$is_cnogood = (isset($boset['na_cnogood']) && $boset['na_cnogood']) ? true : false;
?>
<?php if (!isset($is_ajax_comment) || !$is_ajax_comment) { // 1번만 출력
?>
<script>
// 글자수 제한
var char_min = parseInt(<?php echo $comment_min ?>); // 최소
var char_max = parseInt(<?php echo $comment_max ?>); // 최대
</script>
<!-- 댓글 시작 { -->
<div id="viewcomment">
<?php } ?>
<div class="clearfix f-de px-3 px-sm-0 pt-4 pt-sm-5 pb-1">
<div class="float-left">
댓글 <b class="orangered"><?php echo $write['wr_comment'] ?></b>개
<?php if ($is_paging && $page) { ?>
/ <?php echo $page ?>페이지
<?php } ?>
</div>
<?php if ($is_paging) { //페이징
$cmt_sort_href = NA_URL . '/bbs/comment_view.php?bo_table=' . $bo_table . '&wr_id=' . $wr_id;
switch ($cob) {
case 'new':
$cmt_sort_txt = '최신순';
break;
case 'good':
$cmt_sort_txt = '추천순';
break;
case 'nogood':
$cmt_sort_txt = '비추천순';
break;
default:
$cmt_sort_txt = '과거순';
break;
}
?>
<div class="float-right dropdown">
<a href="javascript:;" class="dropdown-toggle dropdown-toggle-empty" id="cmt_sort" data-toggle="dropdown"
data-display="static" aria-haspopup="true" aria-expanded="false">
<i class="fa fa-caret-down text-muted" aria-hidden="true"></i>
<?php echo $cmt_sort_txt ?>
</a>
<div class="dropdown-menu dropdown-menu-right p-0 border-0 bg-transparent text-right f-de"
aria-labelledby="cmt_sort">
<div class="btn-group-vertical bg-white border py-1 rounded">
<button onclick="na_comment_sort('viewcomment', '<?php echo $cmt_sort_href ?>', 'old');"
class="btn px-3 py-1 text-left" role="button">
과거순
</button>
<button onclick="na_comment_sort('viewcomment', '<?php echo $cmt_sort_href ?>', 'new');"
class="btn px-3 py-1 text-left" role="button">
최신순
</button>
<?php if ($is_cgood) { ?>
<button onclick="na_comment_sort('viewcomment', '<?php echo $cmt_sort_href ?>', 'good');"
class="btn px-3 py-1 text-left" role="button">
추천순
</button>
<?php } ?>
<?php if ($is_cnogood) { ?>
<button onclick="na_comment_sort('viewcomment', '<?php echo $cmt_sort_href ?>', 'nogood');"
class="btn px-3 py-1 text-left" role="button">
비추천순
</button>
<?php } ?>
</div>
</div>
</div>
<?php } ?>
</div>
<section id="bo_vc" class="na-fadein">
<?php
// 댓글목록
$cmt_amt = count($list);
for ($i = 0; $i < $cmt_amt; $i++) {
$comment_id = $list[$i]['wr_id'];
$cmt_depth = strlen($list[$i]['wr_comment_reply']) * 20;
$comment = $list[$i]['content'];
/*
if (strstr($list[$i]['wr_option'], "secret")) {
$str = $str;
}
*/
// 이미지
$comment = preg_replace("/\[\<a\s*href\=\"(http|https|ftp)\:\/\/([^[:space:]]+)\.(gif|png|jpg|jpeg|bmp)\"\s*[^\>]*\>[^\s]*\<\/a\>\]/i", "<img src=\"$1://$2.$3\" alt=\"\" class=\"img-fluid\">", $comment);
// 동영상
$comment = preg_replace("/\[\<a\s.*href\=\"(http|https|ftp|mms)\:\/\/([^[:space:]]+)\.(mp3|wma|wmv|asf|asx|mpg|mpeg)\".*\<\/a\>\]/i", "<script>doc_write(obj_movie('$1://$2.$3'));</script>", $comment);
// 컨텐츠
$comment = na_content($comment);
$cmt_sv = $cmt_amt - $i + 1; // 댓글 헤더 z-index 재설정 ie8 이하 사이드뷰 겹침 문제 해결
$c_reply_href = $comment_common_url . '&c_id=' . $comment_id . '&w=c#bo_vc_w';
$c_edit_href = $comment_common_url . '&c_id=' . $comment_id . '&w=cu#bo_vc_w';
$is_comment_reply_edit = ($list[$i]['is_reply'] || $list[$i]['is_edit'] || $list[$i]['is_del']) ? 1 : 0;
$cmt_shingo = (IS_NA_BBS && $boset['na_shingo']) ? true : false;
$by_writer = ($view['mb_id'] && $view['mb_id'] == $list[$i]['mb_id']) ? ' by-writer' : '';
?>
<?php
$comment_list = sql_fetch("SELECT * FROM g5_member WHERE mb_id = '{$list[$i]['mb_id']}'");
?>
<article id="c_<?php echo $comment_id ?>"
<?php if ($cmt_depth) { ?>style="margin-left:<?php echo $cmt_depth ?>px;" <?php } ?>>
<div class="cmt-wrap position-relative mb-2">
<?php if ($cmt_depth) { ?>
<div class="cmt-reply position-absolute mt-1">
<span class="na-icon na-reply"></span>
</div>
<?php } ?>
<header style="z-index:<?php echo $cmt_sv; ?>">
<h2 class="sr-only">
<?php echo get_text($list[$i]['wr_name']); ?>님의 <?php if ($cmt_depth) { ?><span
class="sr-only">댓글의</span><?php } ?> 댓글
</h2>
<div
class="clearfix font-weight-normal bg-light border-top text-muted f-sm px-3 py-2<?php echo $by_writer ?>">
<ul class="d-flex align-items-center">
<li class="pr-2">
<?php if ($_REQUEST['bo_table'] == 'qanda' && $member['mb_id'] == 'admin') { ?>
<?php echo na_name_photo($list[$i]['mb_id'], $list[$i]['name']); ?>(<?= $comment_list['mb_nick'] ?>)
<?php } else { ?>
<?php echo na_name_photo($list[$i]['mb_id'], $list[$i]['name']); ?>
<?php } ?>
<?php include(G5_SNS_PATH . '/view_comment_list.sns.skin.php'); // SNS
?>
</li>
<?php if ($is_ip_view) { ?>
<?php if ($admin_href) { ?>
<li class="pr-2">
<span class="sr-only">아이피</span>
<span class="f-xs text-muted"><?php echo $list[$i]['ip'] ?></span>
</li>
<?php } ?>
<?php } ?>
</li>
<li class="flex-grow-1 text-right">
<span class="sr-only">작성일</span>
<time class="f-xs"
datetime="<?php echo date('Y-m-d\TH:i:s+09:00', strtotime($list[$i]['wr_datetime'])) ?>"><?php echo na_date($list[$i]['wr_datetime'], 'orangered', 'H:i', 'm.d H:i', 'Y.m.d H:i'); ?></time>
</li>
</ul>
</div>
</header>
<!-- 댓글 출력 -->
<div class="cmt-content p-3">
<?php if (IS_NA_BBS && $is_admin && isset($list[$i]['as_type']) && $list[$i]['as_type'] == "-1") { // 신고처리
?>
<p class="text-danger font-weight-bold">신고처리된 댓글입니다.</p>
<?php } ?>
<?php
$is_lock = false;
if (strstr($list[$i]['wr_option'], "secret")) {
$is_lock = true;
?>
<span class="na-icon na-secret"></span>
<?php } ?>
<?php echo $comment ?>
</div>
<?php if (!$is_lock && (int)$list[$i]['wr_10']) { // 럭키포인트
?>
<div class="f-sm text-muted px-3 my-2">
<i class="fa fa-gift" aria-hidden="true"></i>
<b class="orangered"><?php echo number_format($list[$i]['wr_10']) ?></b> 럭키포인트 당첨!
</div>
<?php } ?>
<?php if ($is_comment_reply_edit || $cmt_shingo || $is_cgood || $is_cnogood) {
if ($w == 'cu') {
$sql = " select wr_id, wr_content, mb_id from $write_table where wr_id = '$c_id' and wr_is_comment = '1' ";
$cmt = sql_fetch($sql);
if (!($is_admin || ($member['mb_id'] == $cmt['mb_id'] && $cmt['mb_id'])))
$cmt['wr_content'] = '';
$c_wr_content = $cmt['wr_content'];
}
?>
<div class="cmt-btn clearfix font-weight-normal px-3">
<ul class="float-right">
<?php if ($list[$i]['is_reply']) { ?>
<li><a href="javascript:;"
onclick="comment_box('<?php echo $comment_id ?>','c'); return false;">답글</a></li>
<?php } ?>
<?php if ($list[$i]['is_edit']) { ?>
<li><a href="javascript:;"
onclick="comment_box('<?php echo $comment_id ?>','cu'); return false;">수정</a></li>
<?php } ?>
<?php if ($list[$i]['is_del']) { ?>
<li><a href="<?php echo $list[$i]['del_link']; ?>"
onclick="<?php echo (isset($list[$i]['del_back']) && $list[$i]['del_back']) ? "na_delete('viewcomment', '" . $list[$i]['del_href'] . "','" . $list[$i]['del_back'] . "'); return false;" : "return comment_delete();"; ?>">삭제</a>
</li>
<?php } ?>
<?php if ($cmt_shingo) { ?>
<li><a href="javascript:;"
onclick="na_shingo('<?php echo $bo_table ?>','<?php echo $comment_id ?>','<?php echo $wr_id ?>'); return false;">신고</a>
</li>
<?php } ?>
<?php if ($is_cgood || $is_cnogood) { ?>
<li class="no-bar p-0">
<?php if ($is_cgood) { ?>
<a href="javascript:;" class="na-cgood"
onclick="na_good('<?php echo $bo_table ?>', '<?php echo $comment_id ?>', 'good', 'c_g<?php echo $comment_id ?>', 1);"
title="추천"> <span class="sr-only">추천</span><b id="c_g<?php echo $comment_id ?>"
class="orangered"><?php echo $list[$i]['wr_good'] ?></b></a><?php } ?><?php if ($is_cnogood) { ?><a
href="javascript:;" class="na-cnogood"
onclick="na_good('<?php echo $bo_table ?>', '<?php echo $comment_id ?>', 'nogood', 'c_ng<?php echo $comment_id ?>', 1);"
title="비추천"><span class="sr-only">비추천</span><b
id="c_ng<?php echo $comment_id; ?>"><?php echo $list[$i]['wr_nogood']; ?></b>
</a>
<?php } ?>
</li>
<?php } ?>
</ul>
</div>
<?php } ?>
<div class="clearfix pl-3">
<span id="edit_<?php echo $comment_id ?>" class="bo_vc_w"></span><!-- 수정 -->
<span id="reply_<?php echo $comment_id ?>" class="bo_vc_re"></span><!-- 답변 -->
<?php if ($is_paging) { ?>
<input type="hidden" value="<?php echo $comment_url . '&page=' . $page; ?>"
id="comment_url_<?php echo $comment_id ?>">
<input type="hidden" value="<?php echo $page; ?>" id="comment_page_<?php echo $comment_id ?>">
<?php } ?>
<input type="hidden" value="<?php echo strstr($list[$i]['wr_option'], "secret") ?>"
id="secret_comment_<?php echo $comment_id ?>">
<textarea id="save_comment_<?php echo $comment_id ?>"
style="display:none"><?php echo get_text($list[$i]['content1'], 0) ?></textarea>
</div>
</div>
</article>
<?php } ?>
<?php if (!$cmt_amt) { //댓글이 없다면 : 숨김처리함
?>
<div id="bo_vc_empty" class="f-de font-weight-normal text-center text-muted border-top px-3 py-5">
등록된 댓글이 없습니다.
</div>
<?php } ?>
<?php if ($is_paging) { //페이징
?>
<div class="border-top font-weight-normal pb-3">
<div class="row">
<div class="col-md-9 pt-3">
<ul class="pagination justify-content-center justify-content-md-start en">
<?php echo na_ajax_paging('viewcomment', $write_pages, $page, $total_page, $comment_page); ?>
</ul>
</div>
<div class="col-md-3 pt-3">
<div class="px-3 px-sm-0">
<button class="btn btn-basic btn-block"
onclick="na_comment_new('viewcomment','<?php echo $comment_url ?>','<?php echo $total_count ?>');">
새로운 댓글 확인
</button>
</div>
</div>
</div>
</div>
<?php } ?>
</section>
<?php if (!$is_ajax_comment) { // 1번만 출력
?>
</div><!-- #viewcomment 닫기 -->
<!-- } 댓글 끝 -->
<?php if ($is_comment_write) {
if ($w == '')
$w = 'c';
?>
<!-- 댓글 쓰기 시작 { -->
<aside id="bo_vc_w">
<h2 class="sr-only">댓글쓰기</h2>
<form id="fviewcomment" name="fviewcomment" action="<?php echo $comment_action_url; ?>"
onsubmit="return fviewcomment_submit(this);" method="post" autocomplete="off"
class="cmt-form font-weight-normal">
<input type="hidden" name="w" value="<?php echo $w ?>" id="w">
<input type="hidden" name="bo_table" value="<?php echo $bo_table ?>">
<input type="hidden" name="wr_id" value="<?php echo $wr_id ?>">
<input type="hidden" name="comment_id" value="<?php echo $c_id ?>" id="comment_id">
<?php if ($is_paging) { //페이징
?>
<input type="hidden" name="comment_url" value="" id="comment_url">
<input type="hidden" name="cob" value="<?php echo $cob ?>">
<?php } ?>
<input type="hidden" name="sca" value="<?php echo $sca ?>">
<input type="hidden" name="sfl" value="<?php echo $sfl ?>">
<input type="hidden" name="stx" value="<?php echo $stx ?>">
<input type="hidden" name="spt" value="<?php echo $spt ?>">
<input type="hidden" name="page" value="<?php echo $page ?>" id="comment_page">
<input type="hidden" name="is_good" value="">
<div class="cmt-box p-3 bg-light border na-round">
<?php if ($is_guest) { ?>
<div class="row mx-n1">
<div class="col-6 px-1">
<div class="form-group mb-2">
<label for="wr_name" class="sr-only">이름<strong class="sr-only"> 필수</strong></label>
<div class="input-group">
<div class="input-group-prepend">
<span class="input-group-text"><i class="fa fa-user text-muted"
aria-hidden="true"></i></span>
</div>
<input type="text" name="wr_name" value="<?php echo get_cookie("ck_sns_name"); ?>"
id="wr_name" class="form-control" maxLength="20" placeholder="이름">
</div>
</div>
</div>
<div class="col-6 px-1">
<div class="form-group mb-2">
<label for="wr_password" class="sr-only">비밀번호<strong class="sr-only"> 필수</strong></label>
<div class="input-group">
<div class="input-group-prepend">
<span class="input-group-text"><i class="fa fa-lock text-muted"
aria-hidden="true"></i></span>
</div>
<input type="password" name="wr_password" id="wr_password" class="form-control"
maxLength="20" placeholder="비밀번호">
</div>
</div>
</div>
</div>
<?php } ?>
<?php if ($comment_min || $comment_max) { ?>
<div class="text-muted f-sm mb-2" id="char_cnt">
<i class="fa fa-commenting-o fa-lg"></i>
현재 <b class="orangered"><span id="char_count">0</span></b>글자
/
<?php if ($comment_min) { ?>
<?php echo number_format((int)$comment_min); ?>글자 이상
<?php } ?>
<?php if ($comment_max) { ?>
<?php echo number_format((int)$comment_max); ?>글자 이하
<?php } ?>
</div>
<?php } ?>
<?php
$reply1 = array(
'안녕하세요.',
);
$randint1 = mt_rand(0, count($reply1) - 1);
$cc_1 = $reply1[$randint1];
?>
<?php if (!$c_wr_content) $c_wr_content = "$cc_1"; ?>
<div class="input-group mb-3">
<textarea id="wr_content" name="wr_content" maxlength="10000" rows="4" class="form-control" cols="33"
<?php if ($comment_min || $comment_max) { ?>onkeyup="check_byte('wr_content', 'char_count');"
<?php } ?>><?php echo $c_wr_content; ?></textarea>
<?php
/*
<?php if ($comment_min || $comment_max) { ?><script>
check_byte('wr_content', 'char_count');
</script><?php } ?>
&nb
답변 2
아~ ㅋ 뭔가 허무하네요 ㅎ
select 구문에서 해당 컬럼을 desc 만 해주면 간단하게 해결 될 것 같습니다^^
댓글 최신순 정렬을 view_comment_skin.php파일에서 수정하는줄 알았는데 아니였네요^^;
https://gnustudy.com/bbs/board.php?bo_table=skin_board&wr_id=193
댓글 최신순으로 정렬법이 있었네요 ㅎㅎ