< 그누보드 카테고리별로 공지 보이게 하기 >
설명은 아래에 있음!
변경 전 /bbs/list.php
// 공지 처리
if (!$is_search_bbs) {
$arr_notice = explode(',', trim($board['bo_notice']));
$from_notice_idx = ($page - 1) * $page_rows;
if($from_notice_idx < 0)
$from_notice_idx = 0;
$board_notice_count = count($arr_notice);
for ($k=0; $k<$board_notice_count; $k++) {
if (trim($arr_notice[$k]) == '') continue;
$row = sql_fetch(" select * from {$write_table} where wr_id = '{$arr_notice[$k]}' ");
if (!isset($row['wr_id']) || !$row['wr_id']) continue;
$notice_array[] = $row['wr_id'];
if($k < $from_notice_idx) continue;
$list[$i] = get_list($row, $board, $board_skin_url, G5_IS_MOBILE ? $board['bo_mobile_subject_len'] : $board['bo_subject_len']);
$list[$i]['is_notice'] = true;
$list[$i]['num'] = 0;
$i++;
$notice_count++;
if($notice_count >= $list_page_rows)
break;
}
}
$total_page = ceil($total_count / $page_rows); // 전체 페이지 계산
$from_record = ($page - 1) * $page_rows; // 시작 열을 구함
// 공지글이 있으면 변수에 반영
if(!empty($notice_array)) {
$from_record -= count($notice_array);
if($from_record < 0)
$from_record = 0;
if($notice_count > 0)
$page_rows -= $notice_count;
if($page_rows < 0)
$page_rows = $list_page_rows;
}
// 관리자라면 CheckBox 보임
$is_checkbox = false;
if ($is_member && ($is_admin == 'super' || $group['gr_admin'] == $member['mb_id'] || $board['bo_admin'] == $member['mb_id']))
$is_checkbox = true;
// 정렬에 사용하는 QUERY_STRING
$qstr2 = 'bo_table='.$bo_table.'&sop='.$sop;
// 0 으로 나눌시 오류를 방지하기 위하여 값이 없으면 1 로 설정
$bo_gallery_cols = $board['bo_gallery_cols'] ? $board['bo_gallery_cols'] : 1;
$td_width = (int)(100 / $bo_gallery_cols);
// 정렬
// 인덱스 필드가 아니면 정렬에 사용하지 않음
//if (!$sst || ($sst && !(strstr($sst, 'wr_id') || strstr($sst, "wr_datetime")))) {
if (!$sst) {
if ($board['bo_sort_field']) {
$sst = $board['bo_sort_field'];
} else {
$sst = "wr_num, wr_reply";
$sod = "";
}
} else {
$board_sort_fields = get_board_sort_fields($board, 1);
if (!$sod && array_key_exists($sst, $board_sort_fields)) {
$sst = $board_sort_fields[$sst];
} else {
// 게시물 리스트의 정렬 대상 필드가 아니라면 공백으로 (nasca 님 09.06.16)
// 리스트에서 다른 필드로 정렬을 하려면 아래의 코드에 해당 필드를 추가하세요.
// $sst = preg_match("/^(wr_subject|wr_datetime|wr_hit|wr_good|wr_nogood)$/i", $sst) ? $sst : "";
$sst = preg_match("/^(wr_datetime|wr_hit|wr_good|wr_nogood)$/i", $sst) ? $sst : "";
}
}
if(!$sst)
$sst = "wr_num, wr_reply";
if ($sst) {
$sql_order = " order by {$sst} {$sod} ";
}
if ($is_search_bbs) {
$sql = " select distinct wr_parent from {$write_table} where {$sql_search} {$sql_order} limit {$from_record}, $page_rows ";
} else {
$sql = " select * from {$write_table} where wr_is_comment = 0 ";
if(!empty($notice_array))
$sql .= " and wr_id not in (".implode(', ', $notice_array).") ";
$sql .= " {$sql_order} limit {$from_record}, $page_rows ";
}
변경 후 /bbs/list.php
// 공지 처리
if (!$is_search_bbs) {
$arr_notice = explode(',', trim($board['bo_notice']));
}
else {
$arr_notice_ori = explode(',', trim($board['bo_notice']));
$result_c = sql_query(" select wr_id from {$write_table} where {$sql_search} ");
for ($cc=0; $row_c=sql_fetch_array($result_c); $cc++) {
if (in_array($row_c['wr_id'], $arr_notice_ori)) {
$arr_notice[] = $row_c['wr_id'];
}
}
}
$from_notice_idx = ($page - 1) * $page_rows;
if($from_notice_idx < 0)
$from_notice_idx = 0;
if (!empty($arr_notice)) {
$board_notice_count = count($arr_notice);
}else {
$board_notice_count = 0;
}
for ($k=0; $k<$board_notice_count; $k++) {
if (trim($arr_notice[$k]) == '') continue;
$row = sql_fetch(" select * from {$write_table} where wr_id = '{$arr_notice[$k]}' ");
if (!$row['wr_id']) continue;
$notice_array[] = $row['wr_id'];
if($k < $from_notice_idx) continue;
$list[$i] = get_list($row, $board, $board_skin_url, G5_IS_MOBILE ? $board['bo_mobile_subject_len'] : $board['bo_subject_len']);
$list[$i]['is_notice'] = true;
$i++;
$notice_count++;
if($notice_count >= $list_page_rows)
break;
}
$total_page = ceil($total_count / $page_rows); // 전체 페이지 계산
$from_record = ($page - 1) * $page_rows; // 시작 열을 구함
// 공지글이 있으면 변수에 반영
if(!empty($notice_array)) {
$from_record -= count($notice_array);
if($from_record < 0)
$from_record = 0;
if($notice_count > 0)
$page_rows -= $notice_count;
if($page_rows < 0)
$page_rows = $list_page_rows;
}
// 관리자라면 CheckBox 보임
$is_checkbox = false;
if ($is_member && ($is_admin == 'super' || $group['gr_admin'] == $member['mb_id'] || $board['bo_admin'] == $member['mb_id']))
$is_checkbox = true;
// 정렬에 사용하는 QUERY_STRING
$qstr2 = 'bo_table='.$bo_table.'&sop='.$sop;
// 0 으로 나눌시 오류를 방지하기 위하여 값이 없으면 1 로 설정
$bo_gallery_cols = $board['bo_gallery_cols'] ? $board['bo_gallery_cols'] : 1;
$td_width = (int)(100 / $bo_gallery_cols);
// 정렬
// 인덱스 필드가 아니면 정렬에 사용하지 않음
//if (!$sst || ($sst && !(strstr($sst, 'wr_id') || strstr($sst, "wr_datetime")))) {
if (!$sst) {
if ($board['bo_sort_field']) {
$sst = $board['bo_sort_field'];
} else {
$sst = "wr_num, wr_reply";
$sod = "";
}
} else {
$board_sort_fields = get_board_sort_fields($board, 1);
if (!$sod && array_key_exists($sst, $board_sort_fields)) {
$sst = $board_sort_fields[$sst];
} else {
// 게시물 리스트의 정렬 대상 필드가 아니라면 공백으로 (nasca 님 09.06.16)
// 리스트에서 다른 필드로 정렬을 하려면 아래의 코드에 해당 필드를 추가하세요.
// $sst = preg_match("/^(wr_subject|wr_datetime|wr_hit|wr_good|wr_nogood)$/i", $sst) ? $sst : "";
$sst = preg_match("/^(wr_datetime|wr_hit|wr_good|wr_nogood)$/i", $sst) ? $sst : "";
}
}
if(!$sst)
$sst = "wr_num, wr_reply";
if ($sst) {
$sql_order = " order by {$sst} {$sod} ";
}
if ($is_search_bbs) {
$sql = " select distinct wr_parent from {$write_table} where {$sql_search}";
if(!empty($notice_array)) {
$sql .= " and wr_id not in (".implode(', ', $notice_array).") ";
}
$sql .= " {$sql_order} limit {$from_record}, $page_rows ";
} else {
$sql = " select * from {$write_table} where wr_is_comment = 0 ";
if(!empty($notice_array)) {
$sql .= " and wr_id not in (".implode(', ', $notice_array).") ";
}
$sql .= " {$sql_order} limit {$from_record}, $page_rows ";
}
전체 페이지에서는 공지 표시가 되는데, 카테고리로 들어가면 공지 표시가 사라진다.
/bbs/list.php 에서 카테고리를 포함한 검색 조건이 있는 경우 공지를 표시하지 않게 되어있기 때문이다.
1. 검색조건이 있어도 공지가 표시되게 변경
변경 전 /bbs/list.php
// 공지 처리
if (!$is_search_bbs) {
$arr_notice = explode(',', trim($board['bo_notice']));
$from_notice_idx = ($page - 1) * $page_rows;
if($from_notice_idx < 0)
$from_notice_idx = 0;
$board_notice_count = count($arr_notice);
for ($k=0; $k<$board_notice_count; $k++) {
if (trim($arr_notice[$k]) == '') continue;
$row = sql_fetch(" select * from {$write_table} where wr_id = '{$arr_notice[$k]}' ");
if (!$row['wr_id']) continue;
$notice_array[] = $row['wr_id'];
if($k < $from_notice_idx) continue;
$list[$i] = get_list($row, $board, $board_skin_url, G5_IS_MOBILE ? $board['bo_mobile_subject_len'] : $board['bo_subject_len']);
$list[$i]['is_notice'] = true;
$i++;
$notice_count++;
if($notice_count >= $list_page_rows)
break;
}
}
변경 후 /bbs/list.php
// 공지 처리
if (!$is_search_bbs) {
$arr_notice = explode(',', trim($board['bo_notice']));
}
else {
$arr_notice_ori = explode(',', trim($board['bo_notice']));
$result_c = sql_query(" select wr_id from {$write_table} where {$sql_search} ");
for ($cc=0; $row_c=sql_fetch_array($result_c); $cc++) {
if (in_array($row_c['wr_id'], $arr_notice_ori)) {
$arr_notice[] = $row_c['wr_id'];
}
}
}
$from_notice_idx = ($page - 1) * $page_rows;
if($from_notice_idx < 0)
$from_notice_idx = 0;
if (!empty($arr_notice)) {
$board_notice_count = count($arr_notice);
}else {
$board_notice_count = 0;
}
for ($k=0; $k<$board_notice_count; $k++) {
if (trim($arr_notice[$k]) == '') continue;
$row = sql_fetch(" select * from {$write_table} where wr_id = '{$arr_notice[$k]}' ");
if (!$row['wr_id']) continue;
$notice_array[] = $row['wr_id'];
if($k < $from_notice_idx) continue;
$list[$i] = get_list($row, $board, $board_skin_url, G5_IS_MOBILE ? $board['bo_mobile_subject_len'] : $board['bo_subject_len']);
$list[$i]['is_notice'] = true;
$i++;
$notice_count++;
if($notice_count >= $list_page_rows)
break;
}
참고) 변경 전 소스에서 if(!$is_search_bbs) 조건만 주석처리하게 되면 카테고리와 상관없이 모든 공지가 카테고리마다 따라온다.
공지 게시글이 목록과 상위에 중복으로 노출되기 때문에 번호가 맞지않는다.
3. 중복 건은 목록에서 제외시킨다.
변경전 /bbs/list.php
if ($is_search_bbs) {
$sql = " select distinct wr_parent from {$write_table} where {$sql_search} {$sql_order} limit {$from_record}, $page_rows ";
} else {
$sql = " select * from {$write_table} where wr_is_comment = 0 ";
if(!empty($notice_array)) {
$sql .= " and wr_id not in (".implode(', ', $notice_array).") ";
}
$sql .= " {$sql_order} limit {$from_record}, $page_rows ";
}
변경 후 /bbs/list.php
if ($is_search_bbs) {
$sql = " select distinct wr_parent from {$write_table} where {$sql_search}";
if(!empty($notice_array)) {
$sql .= " and wr_id not in (".implode(', ', $notice_array).") ";
}
$sql .= " {$sql_order} limit {$from_record}, $page_rows ";
} else {
$sql = " select * from {$write_table} where wr_is_comment = 0 ";
if(!empty($notice_array)) {
$sql .= " and wr_id not in (".implode(', ', $notice_array).") ";
}
$sql .= " {$sql_order} limit {$from_record}, $page_rows ";
}
반응형
'개발하는 '정' > PHP' 카테고리의 다른 글
[PHP] 라라벨 쿼리 출력 (0) | 2022.08.17 |
---|---|
[PHP] 그누보드 정보수정 비밀번호 확인 건너뛰기 (1) | 2022.08.17 |
ADOdb 테이블 생성, 변경, 삭제 + 데이터 조회, 처리 (0) | 2022.03.15 |
PHP 그누보드5 관리자 메뉴 새창으로 열기 (0) | 2022.03.04 |
PHP/MYSQL rownum으로 쿼리 출력한 순서대로 이전글 다음 글 구하기 (0) | 2022.02.22 |
댓글