[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번 추출하도록 쿼리가 만들어져 있는데 위의 두 줄처럼 바꾸면
한번의 쿼리로 가능하게 되니 변경하는 것이 좋겠습니다
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개
12년 전
이런기능 찾는분들 많으시던데... 좋은팁 ^^ 추천합니다.
12년 전
저도 추천하고 갈게요 ^^
kimch
12년 전
균이님 감사합니다.
하나만 여쭤볼께요
말씀대로 latest.lib.php 열어서 위 소스 추가하고
<?=latest_notice('notice', 'notice', 1, 40);?> 이렇게 불러 왔는데 만약 공지사항이 해당 게시판에 2개면 2개가 모두 나옵니다.
또, 2개 였다가 하나를 빼면 공란으로 나옵니다.
갯수대로 나오게 하고 잘 나오게 하려면 어떻게 수정하면 좋을까요?
아님 공지사항이 1개 이상이어야 나오는걸까요?
균이님 수고스러우시겠지만 댓글 한번 부탁 드릴께요
하나만 여쭤볼께요
말씀대로 latest.lib.php 열어서 위 소스 추가하고
<?=latest_notice('notice', 'notice', 1, 40);?> 이렇게 불러 왔는데 만약 공지사항이 해당 게시판에 2개면 2개가 모두 나옵니다.
또, 2개 였다가 하나를 빼면 공란으로 나옵니다.
갯수대로 나오게 하고 잘 나오게 하려면 어떻게 수정하면 좋을까요?
아님 공지사항이 1개 이상이어야 나오는걸까요?
균이님 수고스러우시겠지만 댓글 한번 부탁 드릴께요
12년 전
limit 0, $rows 추가하면 원하는 갯수만큼 나오게 되겠죠
스피드애드
12년 전
감사합니다^^
putty
11년 전
균이님, 죄송합니다만 아래와 같은 에러가 발생하는데 왜 이런 걸까요..
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
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
11년 전
notice 게시판이 없다는 에러 입니다
게시판이 없으니 원래 것 <?=latest(~~~);?><--이걸로 해도 똑같은 에러가 나올 것 입니다
게시판이 없으니 원래 것 <?=latest(~~~);?><--이걸로 해도 똑같은 에러가 나올 것 입니다
9년 전
오늘 자료덕을 많이 받았습니다. 감사합니다.
7년 전
성공적으로 적용
게시판 목록
그누4 팁자료실
그누보드4와 관련된 팁을 여러분들과 함께 공유하세요.
나누면 즐거움이 커집니다.
나누면 즐거움이 커집니다.
| 번호 | 제목 | 글쓴이 | 날짜 | 조회 |
|---|---|---|---|---|
| 3129 | 12년 전 | 5175 | ||
| 3128 | 12년 전 | 7911 | ||
| 3127 | 12년 전 | 7063 | ||
| 3126 | 12년 전 | 4985 | ||
| 3125 | 12년 전 | 5869 | ||
| 3124 | 12년 전 | 5556 | ||
| 3123 | 12년 전 | 5924 | ||
| 3122 | 12년 전 | 6169 | ||
| 3121 | 12년 전 | 5518 | ||
| 3120 | 12년 전 | 5815 | ||
| 3119 | 12년 전 | 5238 | ||
| 3118 | 12년 전 | 4673 | ||
| 3117 | 12년 전 | 4447 | ||
| 3116 | 12년 전 | 7208 | ||
| 3115 | 12년 전 | 6032 | ||
| 3114 |
생각하는바보
|
12년 전 | 6412 | |
| 3113 |
|
12년 전 | 4822 | |
| 3112 |
|
12년 전 | 5207 | |
| 3111 |
|
12년 전 | 3641 | |
| 3110 |
|
12년 전 | 4081 |
댓글 작성
댓글을 작성하시려면 로그인이 필요합니다.
로그인하기