게시글 작성자가 댓글을 고정하게 해보자
작업버전
5.5.8.2.7
추가된 파일 (첨부파일에서 다운로드)
bbs/ajax.commentfix.php
수정한 원본파일
bbs/view_comment.php
skin/board/basic/style.css
skin/board/basic/view.comment.skin.php

유튜브에 보면 영상 업로더가 댓글 고정하는 기능 있죠?
생각나서 얼른 한 번 구현해 봤습니다.
댓글 고정 이후 재접속 때 고정처리를 스크립트로 하는 방법인데,
빨리 구현하려고 그렇게 했습니다. ㅎ
간단히 말해서 댓글 레코드의 wr_1 에 값이 있으면 고정시키는 방식입니다.
하나의 댓글만 고정할 수 있습니다.
여러개 고정하려면 조금 손을 더 봐야겠네요... ㅎ
자 그럼 수정을 시작해 볼까요?

bbs/view_comment.php
69라인 쯤에
[code]$list[$i]['is_fix'] = false; // 얘 추가
$list[$i]['is_reply'] = false; // 여기 위에[/code]
98라인 쯤에 추가
[code] if ($member['mb_id'] === $view['mb_id'] || $is_admin) {
$list[$i]['is_fix'] = true;
}[/code]
skin/board/basic/style.css
이 부분을
[code].bo_vc_act li a {display:inline-block;padding:10px 15px}
.bo_vc_act li a:hover {color:#3a8afd}[/code]
아래처럼 수정
[code].bo_vc_act li a, .bo_vc_act li button {display:inline-block;margin:0;padding:10px 15px;border:0;background:none}
.bo_vc_act li a:hover, .bo_vc_act li button:hover {color:#3a8afd}
#bo_vc_fix .desc {margin:0 0 -10px;padding:10px 0 0;font-weight:bold}[/code]
skin/board/basic/view.comment.skin.php
1) 이 부분 다음에
[code]<section id="bo_vc">
<h2>댓글목록</h2>[/code]
아래를 추가
[code] <div id="bo_vc_fix">
<div class="desc" style="display:none"><i class="fa fa-map-pin"></i> 작성자가 고정한 댓글</div>
<div class="container"></div>
</div>[/code]
2) 이 부분을
[code]$is_comment_reply_edit = ($list[$i]['is_reply'] || $list[$i]['is_edit'] || $list[$i]['is_del']) ? 1 : 0;[/code]
아래처럼 수정
[code]$is_comment_reply_edit = ($list[$i]['is_fix'] || $list[$i]['is_reply'] || $list[$i]['is_edit'] || $list[$i]['is_del']) ? 1 : 0;[/code]
3) 이 부분을
[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 id="c_<?php echo $comment_id ?>" <?php if ($list[$i]['wr_1']) { ?>class="fix"<?php } ?> <?php if ($cmt_depth) { ?>style="margin-left:<?php echo $cmt_depth ?>px;border-top-color:#e0e0e0"<?php } ?>>[/code]
4) 이 부분 다음에
[code] <ul class="bo_vc_act">[/code]
아래를 추가
[code] <?php if ($list[$i]['is_fix']) { ?><li><button type="button" class="btn_cm_fix" data-wrid="<?php echo $comment_id; ?>">상단고정</button></li><?php } ?>[/code]
5) 이 부분을
[code]<script>
jQuery(function($) {
//댓글열기
$(".cmt_btn").click(function(e){
e.preventDefault();
$(this).toggleClass("cmt_btn_op");
$("#bo_vc").toggle();
});
});
</script>[/code]
아래로 수정
[code]<script>
jQuery(function($) {
//댓글열기
$(".cmt_btn").click(function(e){
e.preventDefault();
$(this).toggleClass("cmt_btn_op");
$("#bo_vc").toggle();
});
$(".btn_cm_fix").click(function(){
if (confirm("이 댓글을 고정하시겠습니까?")) {
var
$this = $(this),
co_id = $this.data('wrid'),
co_parent_id = <?php echo $view['wr_parent']; ?>;
$.ajax({
type: "POST",
dataType: "json",
url: "<?php echo G5_BBS_URL; ?>/ajax.commentfix.php",
data: {
bo_table: "<?php echo $bo_table; ?>",
comment_id : co_id,
comment_parent_id: co_parent_id
},
success: function(response) {
if (response.type === "done") {
comment_fix($this, 1);
$(".bo_vc_act").hide();
} else if (response.type === "err") {
alert(response.error);
}
},
error: function() {
return false;
}
});
} else {
return false;
}
});
});
$(document).ready(function(){
var
$fixed_cmt = $("article.fix"),
fixed_cnt = $fixed_cmt.length;
if (fixed_cnt) {
comment_fix($fixed_cmt, 0);
}
});
function comment_fix(el, find) {
var
$el = el,
$fix_el = $("#bo_vc_fix"),
$fix_container = $fix_el.find(".container");
if (find)
var co_clone = $el.closest("article").clone();
else
var co_clone = $el.clone();
$fix_container.html("");
$fix_container.append(co_clone);
$fix_container.find("article").css("margin-left", 0);
$fix_container.find(".bo_vl_opt").remove();
$fix_el.find(".desc").show();
}
</script>[/code]
댓글 7개
게시판 목록
그누보드5 팁자료실
| 번호 | 제목 | 글쓴이 | 날짜 | 조회 |
|---|---|---|---|---|
| 1975 | 4년 전 | 3070 | ||
| 1974 |
그누x즁딩
|
4년 전 | 4070 | |
| 1973 | 4년 전 | 4332 | ||
| 1972 | 4년 전 | 7716 | ||
| 1971 |
|
4년 전 | 3757 | |
| 1970 | 4년 전 | 2840 | ||
| 1969 |
|
4년 전 | 3884 | |
| 1968 | 4년 전 | 4614 | ||
| 1967 | 4년 전 | 11968 | ||
| 1966 | 4년 전 | 2664 | ||
| 1965 | 4년 전 | 3262 | ||
| 1964 |
honbab
|
4년 전 | 2605 | |
| 1963 |
|
4년 전 | 3721 | |
| 1962 | 4년 전 | 2441 | ||
| 1961 | 4년 전 | 2913 | ||
| 1960 | 4년 전 | 3286 | ||
| 1959 |
welcome
|
4년 전 | 3274 | |
| 1958 |
|
4년 전 | 5199 | |
| 1957 | 4년 전 | 3564 | ||
| 1956 |
몰라무서워
|
4년 전 | 3259 | |
| 1955 | 4년 전 | 3503 | ||
| 1954 | 4년 전 | 3077 | ||
| 1953 | 4년 전 | 2531 | ||
| 1952 |
|
4년 전 | 4864 | |
| 1951 |
|
4년 전 | 3341 | |
| 1950 |
|
4년 전 | 4015 | |
| 1949 |
|
4년 전 | 3780 | |
| 1948 |
|
4년 전 | 3409 | |
| 1947 |
|
4년 전 | 3104 | |
| 1946 | 4년 전 | 5786 |
댓글 작성
댓글을 작성하시려면 로그인이 필요합니다.
로그인하기