붉은바람

최신글 공지사항을 최상위,상위,위에 노출하는 latest 함수

그누5 버전 : https://sir.kr/g5_tip/7172

최신글 공지사항을 최상위,상위,위에 노출하는 latest 함수입니다.

다른건 약간에 버그가 있는것 같아, 제가 만들어 봤습니다.

만약 게시판 글이 2개만 있는데 둘다 공지사항글이 2개 일시, 리스트에 4개가 노출됩니다.

그러면 최신글에도 4개가 노출되던데 그 버그 수정하여 올렸습니다.

latest 함수는 latest_notice 이므로 사용하시고자 하신는분들은

함수호출시

<?=latest_notice("basic","free",5,20) ?>

위와같이 함수호출명만 변경하시면 됩니다.


아래의 코드는 /lib/latest.lib.php에 기존거 지우지마시고 밑에다가 추가로 넣어주시면됩니다.


[code]
<?

// 공지글이 최상단에 노출
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; // 게시판 테이블 전체이름
//$sql = " select * from $tmp_write_table where wr_is_comment = 0 order by wr_id desc limit 0, $rows ";
// 위의 코드 보다 속도가 빠름

$arr_notice = explode("\n", trim($board[bo_notice]));

$str_notice = implode("','",$arr_notice);
$str_notice = "'".$str_notice."'";
$sql_search = "";
if(count($str_notice) > 0){
$sql_search = " and wr_id not in ($str_notice) ";
}

$sql = " select * from $tmp_write_table where wr_is_comment = 0 $sql_search order by wr_num limit 0, $rows ";
//explain($sql);
$result = sql_query($sql);

$i = 0;
for ($k=0; $k<count($arr_notice); $k++)
{
if (trim($arr_notice[$k])=='') continue;

$row = sql_fetch(" select * from $tmp_write_table where wr_id = '$arr_notice[$k]' ");

if (!$row[wr_id]) continue;

$list[$i] = get_list($row, $board, $latest_skin_path, $board[bo_subject_len]);
$list[$i][is_notice] = true;

$i++;
}

while ($row = sql_fetch_array($result)){
if($i > $rows){
break;
}
$list[$i] = get_list($row, $board, $latest_skin_path, $subject_len);
$i++;

}

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

return $content;
}

?>
[/code]
|

댓글 2개

공지글 갯수를 지정 할 수는 없나요???
감사합니다^^
댓글을 작성하시려면 로그인이 필요합니다.

그누4 팁자료실

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

+
제목 글쓴이 날짜 조회
12년 전 조회 6,608
12년 전 조회 3,864
12년 전 조회 1.3만
12년 전 조회 1.1만
12년 전 조회 5,452
12년 전 조회 6,218
12년 전 조회 5,646
12년 전 조회 5,618
12년 전 조회 1.2만
12년 전 조회 8,559
12년 전 조회 9,713
12년 전 조회 8,768
12년 전 조회 3,990
12년 전 조회 5,938
12년 전 조회 5,642
12년 전 조회 7,698
12년 전 조회 5,798
12년 전 조회 6,150
12년 전 조회 6,008
12년 전 조회 4,362