테스트 사이트 - 개발 중인 베타 버전입니다

[1원짜리팁] 최신글 공지만 출력하기

공지사항만 최신글로 출력하고자 하는 경우 방법입니다
lib/latest.lib.php에서 latest()함수를 복사하여 latest_notice 함수를 하나 만듭니다
출력은 <?=latest_notice('basic','notice',10,60);?>

latest_notice 함수는 아래와 같이

function latest_notice($skin_dir="", $bo_table, $rows=10, $subject_len=40, $options="")
{
global $g4;

if ($skin_dir) $latest_skin_path = "$g4[path]/skin/latest/$skin_dir";
else $latest_skin_path = "$g4[path]/skin/latest/basic";

$list = array();

$sql = " select * from $g4[board_table] where bo_table = '$bo_table'";
$board = sql_fetch($sql);

$tmp_write_table = $g4['write_prefix'] . $bo_table; // 게시판 테이블 전체이름

//-- 아래 3줄 변경되었습니다
$arr_notice = preg_replace("/\n/",',', trim($board[bo_notice]));
if(!$arr_notice) $arr_notice=0;
$result = sql_query(" select * from $tmp_write_table where wr_id IN($arr_notice) order by wr_num limit 0, $rows");

for ($i=0; $row = sql_fetch_array($result); $i++)
$list[$i] = get_list($row, $board, $latest_skin_path, $subject_len);

ob_start();
include "$latest_skin_path/latest.skin.php";
$content = ob_get_contents();
ob_end_clean();

return $content;
}

-------------
참고로 그누보드 bbs/list.php에서 공지사항 추출하는부분 코드를 보면
공지사항이 10개면 10번 추출하도록 쿼리가 만들어져 있는데 위의 두 줄처럼 바꾸면
한번의 쿼리로 가능하게 되니 변경하는 것이 좋겠습니다

댓글 작성

댓글을 작성하시려면 로그인이 필요합니다.

로그인하기

댓글 9개

이런기능 찾는분들 많으시던데... 좋은팁 ^^ 추천합니다.
저도 추천하고 갈게요 ^^
균이님 감사합니다.

하나만 여쭤볼께요

말씀대로 latest.lib.php 열어서 위 소스 추가하고

<?=latest_notice('notice', 'notice', 1, 40);?> 이렇게 불러 왔는데 만약 공지사항이 해당 게시판에 2개면 2개가 모두 나옵니다.

또, 2개 였다가 하나를 빼면 공란으로 나옵니다.

갯수대로 나오게 하고 잘 나오게 하려면 어떻게 수정하면 좋을까요?
아님 공지사항이 1개 이상이어야 나오는걸까요?

균이님 수고스러우시겠지만 댓글 한번 부탁 드릴께요
limit 0, $rows 추가하면 원하는 갯수만큼 나오게 되겠죠
감사합니다^^
균이님, 죄송합니다만 아래와 같은 에러가 발생하는데 왜 이런 걸까요..

select * from g4_write_notice where wr_id IN(0) order by wr_num limit 0, 10
1146 : Table 'gnuboard.g4_write_notice' doesn't exist
error file : /gnuboard4/index.php
notice 게시판이 없다는 에러 입니다
게시판이 없으니 원래 것 <?=latest(~~~);?><--이걸로 해도 똑같은 에러가 나올 것 입니다
오늘 자료덕을 많이 받았습니다. 감사합니다.

게시판 목록

그누4 팁자료실

그누보드4와 관련된 팁을 여러분들과 함께 공유하세요.
나누면 즐거움이 커집니다.
글쓰기
🐛 버그신고