그누보드 최근글, 최신글 게시판별로 선택한 게시물만 출력하기 | 원하는 게시판 최신글 선택 출력하기
그누보드를 이용해 제작중에 전체 게시판 또는 원하는 게시판의 최신글(최근글)을 뽑아오는 것은 sir 사이트에서 찾을 수 있으나, 관리자가 원하는 게시물만 출력하는 것은 특정 게시판은 가능하나 전체 게시판에서 하는 기능은 찾기 어려웠다.
따라서, all_latest 기능과 특정 게시판의 선택게시물 출력기능(wr_1 이용) 을 조합하여, GPT의 도움으로 만들어 보았다. ( 3번 내용 )
아래는 참고하기 바란다.
1. 원하는 게시판만 선택해서 출력하기
[최신글]원하는 게시판만 선택해서하기 > 그누보드5 팁자료실
[최신글]원하는 게시판만 선택해서하기 > SIR
latest.lib.php 하단에 아래 함수를 추가하시면됩니다. <br/> <br/>[code] <br/>
sir.kr
2. 단일 게시판의 원하는 게시물만 선택해서 출력하기
여분필드를 활용해서 특정 게시물만 최신글로 추출하기 - 최신글스킨강좌, 그누보드5강좌
여분필드를 활용해서 특정 게시물만 최신글로 추출하기 - 최신글스킨강좌, 그누보드5강좌
게시판에 글을 등록할 때 별도로 체크한 게시물만 최신글로 출력하는 방법입니다.수정파일1 : lib/latest.lib.php기존에 있던 최신글 함수를 복사해서 함수명을 다른 이름으로 변경해서 같은 파일 하
gnustudy.com
3. 원하는 게시판의 원하는 게시물만 선택해서 출력하기
1) /lib/latest.lib.php 에 아래의 내용을 추가한다.
<?php
function latest_selected($skin_dir='', $bo_tables, $rows=10, $subject_len=40, $cache_time=1, $options='') {
global $g5;
if (!$skin_dir) $skin_dir = 'basic';
// 스킨 경로 설정
if (preg_match('#^theme/(.+)$#', $skin_dir, $match)) {
$latest_skin_path = (G5_IS_MOBILE) ? G5_THEME_MOBILE_PATH.'/'.G5_SKIN_DIR.'/latest/'.$match[1] : G5_THEME_PATH.'/'.G5_SKIN_DIR.'/latest/'.$match[1];
$latest_skin_url = str_replace(G5_PATH, G5_URL, $latest_skin_path);
$skin_dir = $match[1];
} else {
$latest_skin_path = (G5_IS_MOBILE) ? G5_MOBILE_PATH.'/'.G5_SKIN_DIR.'/latest/'.$skin_dir : G5_SKIN_PATH.'/latest/'.$skin_dir;
$latest_skin_url = (G5_IS_MOBILE) ? G5_MOBILE_URL.'/'.G5_SKIN_DIR.'/latest/'.$skin_dir : G5_SKIN_URL.'/latest/'.$skin_dir;
}
$list = array();
$i = 0;
// 여러 게시판 처리
$bo_table_arr = explode(',', $bo_tables);
foreach ($bo_table_arr as $bo_table) {
$bo_table = trim($bo_table);
$board = sql_fetch("SELECT * FROM {$g5['board_table']} WHERE bo_table = '{$bo_table}'");
if (!$board) continue;
$write_table = $g5['write_prefix'] . $bo_table;
$sql = "SELECT * FROM {$write_table}
WHERE wr_1 = 1
AND wr_id = wr_parent
ORDER BY wr_num DESC, wr_reply ASC
LIMIT {$rows}";
$result = sql_query($sql);
while ($row = sql_fetch_array($result)) {
$list[$i] = get_list($row, $board, $latest_skin_url, $subject_len);
$list[$i]['bo_subject'] = $board['bo_subject'];
$list[$i]['bo_table'] = $bo_table;
$i++;
}
}
ob_start();
include $latest_skin_path.'/latest.skin.php';
$content = ob_get_contents();
ob_end_clean();
return $content;
}
?>
2) 사용하고자 하는 리스트 스킨파일 lastest.skin.php 의 상단 <?php ?> 부분에 아래의 내용을 추가한다.
// 기존 리스트에서 wr_1 값이 1인 게시물만 필터링
$list_filtered = array_filter($list, function($item) {
return isset($item['wr_1']) && $item['wr_1'] == 1;
});
$list_count = count($list_filtered);
$is_partial = false;
3) 출력하고자 하는 index 또는 기타 페이지에서 아래와 같이 불러온다.
<?php echo latest_selected("스킨명", "게시판1, 게시판2, 게시판3, 게시판4", 5, 20 ); ?>
4) 게시판의 write.skin.php 에 아래의 내용을 추가해서 메인출력을 정해준다.
<?php if ($is_admin) { ?>
<div class="write_div">
<label for="wr_1">메인 출력</label>
<input type="checkbox" name="wr_1" id="wr_1" value="1" <?php echo ($wr_1 == 1) ? 'checked' : ''; ?>> 선택된 게시물만 출력
</div>
<?php } ?>
자, 이제 원하는 게시판의 원하는 게시물을 선택해서 메인에 출력이 가능하다. ^^