📖
그누보드5 게시판 리스트(목록)에서 특정 게시글 맨위로 이동
페이지 정보
본문
아직 충분한 테스트/검증이 되지는 않았습니다.
(만약을 위해 작업 전 해당 게시판 DB 백업 후 진행을 권장합니다.)
1. [스킨 디렉토리]/list.skin.php 파일에 다음 코드 추가
📬 제목 출력 부분에 다음코드 추가[code]<?php if ($is_admin && !$list[$i]['is_notice'] && !$list[$i]['wr_reply']) {?>
<button type='button' class='btn_go' title='맨 위로 이동' data-id='<?php echo $list[$i]['wr_id']; ?>' data-table='<?php echo $bo_table; ?>'>🚀</button>
<?php }?>[/code]
📬 하단 자바 스크립트 부분에 다음 코드 추가[code]<script>
document.querySelectorAll('.btn_go').forEach(btn => {
btn.addEventListener('click', function () {
const wr_id = this.dataset.id;
const bo_table = this.dataset.table;
if (!confirm(`📢 글 ID ${wr_id} 를 최상단으로 이동할까요?`)) return;
fetch('<?php echo $board_skin_url; ?>/ajax.num_change.php', {
method: 'POST',
headers: { 'Content-Type': 'application/x-www-form-urlencoded' },
body: 'bo_table=' + encodeURIComponent(bo_table) + '&wr_id=' + encodeURIComponent(wr_id)
})
.then(res => res.text())
.then(alert)
.catch(err => alert('❌ 실패: ' + err));
});
});
</script>[/code]
2. [스킨 디렉토리]/ajax.num_change.php 파일 생성[code]<?php
include_once('../../../common.php'); // 경로확인
// --- 관리자 인증 (로그인 및 최고관리자 확인)
if (!$is_admin || $is_admin != 'super') {
die("📢 접근 권한이 없습니다.");
}
$bo_table = $_POST['bo_table'] ?? '';
$wr_id = (int)($_POST['wr_id'] ?? 0);
if (!preg_match('/^[a-z0-9_]+$/', $bo_table) || !$wr_id) {
die("📢 잘못된 접근");
}
$table = "g5_write_{$bo_table}";
// 본문글인지 체크
$row = sql_fetch("SELECT wr_is_comment, wr_num FROM {$table} WHERE wr_id = '{$wr_id}'");
if (!$row || $row['wr_is_comment']) {
die("📢 본문 글이 아닙니다.");
}
$current_wr_num = (int)$row['wr_num'];
// 최상단 wr_num(최솟값) 조회 (본문글만)
$row = sql_fetch("SELECT MIN(wr_num) AS min_wr_num FROM {$table} WHERE wr_is_comment = 0");
$min_wr_num = (int)$row['min_wr_num'];
// 이미 최상단이면 종료
if ($current_wr_num == $min_wr_num) {
echo "📢 글 ID {$wr_id} 는 이미 최상단에 있습니다.";
exit;
}
// 트랜잭션 시작 (가능하면)
sql_query("START TRANSACTION");
// 1) 현재 글 wr_num을 0(임시값)으로 변경 (중복 방지)
sql_query("UPDATE {$table} SET wr_num = 0 WHERE wr_id = '{$wr_id}'");
// 2) 최상단 wr_num부터 현재 wr_num 전까지 글들의 wr_num을 +1씩 밀기 (본문글만)
sql_query("UPDATE {$table} SET wr_num = wr_num + 1 WHERE wr_num >= {$min_wr_num} AND wr_num < {$current_wr_num} AND wr_is_comment = 0");
// 3) 이동 글 wr_num을 최상단 wr_num으로 변경
sql_query("UPDATE {$table} SET wr_num = {$min_wr_num} WHERE wr_id = '{$wr_id}'");
// 4) 댓글들도 wr_num 동일하게 변경 (wr_parent가 wr_id인 경우만)
sql_query("UPDATE {$table} SET wr_num = {$min_wr_num} WHERE wr_parent = '{$wr_id}' AND wr_is_comment = 1");
sql_query("COMMIT");
echo "📢 글 ID {$wr_id} 가 최상단으로 이동되었습니다.";
?>[/code]
(만약을 위해 작업 전 해당 게시판 DB 백업 후 진행을 권장합니다.)
1. [스킨 디렉토리]/list.skin.php 파일에 다음 코드 추가
📬 제목 출력 부분에 다음코드 추가[code]<?php if ($is_admin && !$list[$i]['is_notice'] && !$list[$i]['wr_reply']) {?>
<button type='button' class='btn_go' title='맨 위로 이동' data-id='<?php echo $list[$i]['wr_id']; ?>' data-table='<?php echo $bo_table; ?>'>🚀</button>
<?php }?>[/code]
📬 하단 자바 스크립트 부분에 다음 코드 추가[code]<script>
document.querySelectorAll('.btn_go').forEach(btn => {
btn.addEventListener('click', function () {
const wr_id = this.dataset.id;
const bo_table = this.dataset.table;
if (!confirm(`📢 글 ID ${wr_id} 를 최상단으로 이동할까요?`)) return;
fetch('<?php echo $board_skin_url; ?>/ajax.num_change.php', {
method: 'POST',
headers: { 'Content-Type': 'application/x-www-form-urlencoded' },
body: 'bo_table=' + encodeURIComponent(bo_table) + '&wr_id=' + encodeURIComponent(wr_id)
})
.then(res => res.text())
.then(alert)
.catch(err => alert('❌ 실패: ' + err));
});
});
</script>[/code]
2. [스킨 디렉토리]/ajax.num_change.php 파일 생성[code]<?php
include_once('../../../common.php'); // 경로확인
// --- 관리자 인증 (로그인 및 최고관리자 확인)
if (!$is_admin || $is_admin != 'super') {
die("📢 접근 권한이 없습니다.");
}
$bo_table = $_POST['bo_table'] ?? '';
$wr_id = (int)($_POST['wr_id'] ?? 0);
if (!preg_match('/^[a-z0-9_]+$/', $bo_table) || !$wr_id) {
die("📢 잘못된 접근");
}
$table = "g5_write_{$bo_table}";
// 본문글인지 체크
$row = sql_fetch("SELECT wr_is_comment, wr_num FROM {$table} WHERE wr_id = '{$wr_id}'");
if (!$row || $row['wr_is_comment']) {
die("📢 본문 글이 아닙니다.");
}
$current_wr_num = (int)$row['wr_num'];
// 최상단 wr_num(최솟값) 조회 (본문글만)
$row = sql_fetch("SELECT MIN(wr_num) AS min_wr_num FROM {$table} WHERE wr_is_comment = 0");
$min_wr_num = (int)$row['min_wr_num'];
// 이미 최상단이면 종료
if ($current_wr_num == $min_wr_num) {
echo "📢 글 ID {$wr_id} 는 이미 최상단에 있습니다.";
exit;
}
// 트랜잭션 시작 (가능하면)
sql_query("START TRANSACTION");
// 1) 현재 글 wr_num을 0(임시값)으로 변경 (중복 방지)
sql_query("UPDATE {$table} SET wr_num = 0 WHERE wr_id = '{$wr_id}'");
// 2) 최상단 wr_num부터 현재 wr_num 전까지 글들의 wr_num을 +1씩 밀기 (본문글만)
sql_query("UPDATE {$table} SET wr_num = wr_num + 1 WHERE wr_num >= {$min_wr_num} AND wr_num < {$current_wr_num} AND wr_is_comment = 0");
// 3) 이동 글 wr_num을 최상단 wr_num으로 변경
sql_query("UPDATE {$table} SET wr_num = {$min_wr_num} WHERE wr_id = '{$wr_id}'");
// 4) 댓글들도 wr_num 동일하게 변경 (wr_parent가 wr_id인 경우만)
sql_query("UPDATE {$table} SET wr_num = {$min_wr_num} WHERE wr_parent = '{$wr_id}' AND wr_is_comment = 1");
sql_query("COMMIT");
echo "📢 글 ID {$wr_id} 가 최상단으로 이동되었습니다.";
?>[/code]
댓글목록
등록된 댓글이 없습니다.
![]() ![]() |