리스트(목록)에서 게시글 순서 변경

※ 불량학생님의 팁글을 참고하였습니다.
: https://sir.kr/g5_tip/8789
해당 팁글을 참고하여 제 스타일로 새로이 작성하였습니다.
관리자 로그인 상태에서 게시글 순서 변경 작업이 가능합니다.
아직 충분한 테스트/검증이 되지는 않았습니다.
(만약을 위해 작업 전 해당 게시판 DB 백업 후 진행을 권장합니다.)
오류/보완사항 등이 있다면 댓글로 얘기해 주시면 됩니다.
1. [스킨 디렉토리]/list.skin.php 파일에 다음 코드 추가
1) 제목 출력 부분에 다음코드 추가
[code]
<?php if ($is_admin && !$list[$i]['is_notice'] && !$list[$i]['wr_reply']) { ?>
<input type="text" name="wr_num" size="6" maxlength="10" value="<?php echo $list[$i]['wr_num'] * -1 ?>" data-org="<?php echo $list[$i]['wr_num'] * -1 ?>">
<button type="button" class="btn_go">Go</button>
<?php } ?>
[/code]
2) 자바 스크립트 부분 하단에 다음 코드 추가
[code]
$('input[name="wr_num"]').on('focus', function() {
$(this).select();
});
$('.btn_go').on('click', function() {
let p_bo_table = '<?php echo $bo_table ?>';
let p_wr_num_org = Number($(this).prev().data('org'));
let p_wr_num = Number($(this).prev().val());
if (isNaN(p_wr_num)) {
alert('숫자만 입력해 주세요.');
return false;
}
if (p_wr_num_org == p_wr_num) {
return false;
}
if (p_wr_num < 1) {
alert('0 보다 큰 숫자를 입력해 주세요.');
return false;
}
if (!confirm(p_wr_num + '번 게시글 다음 순서로 이동시키겠습니까?'))
return false;
$.ajax({
url: '<?php echo $board_skin_url ?>/ajax.num_change.php',
type: 'POST',
context: this,
data: {bo_table : p_bo_table, wr_num_org : p_wr_num_org, wr_num : p_wr_num},
success: function(data) {
if (data == 'OK') {
location.reload();
} else if (data == 'Error3') {
alert('없는 게시글 번호 입니다.');
$(this).prev().val(p_wr_num_org);
} else {
alert(data);
}
}
});
});
[/code]
2. [스킨 디렉토리]/ajax.num_change.php 파일 생성
[code]
<?php
$path = '';
for ($i = 0; $i < 7; $i++) {
if (file_exists($path . 'common.php'))
break;
if (realpath($path) == '/')
break;
$path .= '../';
}
include_once($path . 'common.php');
if (!$bo_table || !$wr_num_org || !$wr_num)
die('Error1');
if ($wr_num_org == $wr_num)
die('Error2');
$write_table = $g5['write_prefix'] . $bo_table;
$wr_num = $wr_num * -1;
$wr_num_org = $wr_num_org * -1;
// 1) 이동 '고유번호(wr_num)' 존재 여부 체크
$sql = "select count(*) as cnt from {$write_table} where wr_num = '{$wr_num}' and wr_is_comment = 0";
$row = sql_fetch($sql);
if ($row['cnt'] == 0)
die('Error3');
// 2) 원 게시글의 고유번호를 (임시) '0' 으로 업데이트
$sql = "update {$write_table} set wr_num = '0' where wr_num = '{$wr_num_org}'";
$result_1 = sql_query($sql);
// 3) 관련 이동 대상 게시글들 고유번호 업데이트
if ($wr_num > $wr_num_org) {
$sql = "update {$write_table} set wr_num = wr_num - 1 where wr_num <= '{$wr_num}' and wr_num > '{$wr_num_org}'";
} else if ($wr_num < $wr_num_org) {
$sql = "update {$write_table} set wr_num = wr_num + 1 where wr_num > '{$wr_num}' and wr_num < '{$wr_num_org}'";
}
$result_2 = sql_query($sql);
// 4) (임시) '0' 게시글 고유번호를 새 위치 고유번호로 업데이트
if ($wr_num < $wr_num_org)
$wr_num = $wr_num + 1;
$sql = "update {$write_table} set wr_num = '{$wr_num}' where wr_num = '0'";
$result_3 = sql_query($sql);
$r = $result_1 * $result_2 * $result_3;
if ($r)
echo 'OK';
else
echo 'Error';
[/code]
댓글 6개
오... 글 순서를 바꿔야하는 경우가 있어서 관리자만 볼 수 있는 게시판 만들어두고 거기에 이동시켰다가 운영중인 게시판에 원하는 순서대로 다시 이동시키곤 했었는데, 그럴 필요가 없어지겠네요!!
공유 감사드립니다!
감사합니다
감사합니다
감사합니다.
감사합니다.
좋은 자료 감사 합니다 잘 되네요 ^^
게시판 목록
그누보드5 팁자료실
| 번호 | 제목 | 글쓴이 | 날짜 | 조회 |
|---|---|---|---|---|
| 공지 | 3년 전 | 4402 | ||
| 2574 | 10개월 전 | 559 | ||
| 2573 | 10개월 전 | 936 | ||
| 2572 |
두리삼촌v
|
10개월 전 | 606 | |
| 2571 | 10개월 전 | 554 | ||
| 2570 | 10개월 전 | 598 | ||
| 2569 |
두리삼촌v
|
10개월 전 | 635 | |
| 2568 |
두리삼촌v
|
10개월 전 | 665 | |
| 2567 |
두리삼촌v
|
10개월 전 | 459 | |
| 2566 |
두리삼촌v
|
10개월 전 | 441 | |
| 2565 | 10개월 전 | 738 | ||
| 2564 | 10개월 전 | 666 | ||
| 2563 | 10개월 전 | 472 | ||
| 2562 | 10개월 전 | 1028 | ||
| 2561 |
|
10개월 전 | 674 | |
| 2560 | 10개월 전 | 917 | ||
| 2559 | 10개월 전 | 655 | ||
| 2558 |
|
10개월 전 | 503 | |
| 2557 | 10개월 전 | 656 | ||
| 2556 | 11개월 전 | 953 | ||
| 2555 | 11개월 전 | 1334 | ||
| 2554 | 11개월 전 | 750 | ||
| 2553 |
|
11개월 전 | 744 | |
| 2552 | 11개월 전 | 673 | ||
| 2551 | 11개월 전 | 863 | ||
| 2550 | 11개월 전 | 764 | ||
| 2549 |
|
11개월 전 | 716 | |
| 2548 | 11개월 전 | 1028 | ||
| 2547 | 11개월 전 | 669 | ||
| 2546 | 11개월 전 | 1203 | ||
| 2545 | 11개월 전 | 660 |
댓글 작성
댓글을 작성하시려면 로그인이 필요합니다.
로그인하기