최신글 공지사항을 최상위,상위,위에 노출하는 latest 함수
최신글 공지사항을 최상위,상위,위에 노출하는 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, $cache_time=1, $options='')
{
global $g5;
if (!$skin_dir) $skin_dir = 'basic';
if(preg_match('#^theme/(.+)$#', $skin_dir, $match)) {
if (G5_IS_MOBILE) {
$latest_skin_path = G5_THEME_MOBILE_PATH.'/'.G5_SKIN_DIR.'/latest/'.$match[1];
if(!is_dir($latest_skin_path))
$latest_skin_path = G5_THEME_PATH.'/'.G5_SKIN_DIR.'/latest/'.$match[1];
$latest_skin_url = str_replace(G5_PATH, G5_URL, $latest_skin_path);
} else {
$latest_skin_path = 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 {
if(G5_IS_MOBILE) {
$latest_skin_path = G5_MOBILE_PATH.'/'.G5_SKIN_DIR.'/latest/'.$skin_dir;
$latest_skin_url = G5_MOBILE_URL.'/'.G5_SKIN_DIR.'/latest/'.$skin_dir;
} else {
$latest_skin_path = G5_SKIN_PATH.'/latest/'.$skin_dir;
$latest_skin_url = G5_SKIN_URL.'/latest/'.$skin_dir;
}
}
$cache_fwrite = false;
if(G5_USE_CACHE) {
$cache_file = G5_DATA_PATH."/cache/latest-{$bo_table}-{$skin_dir}-{$rows}-{$subject_len}.php";
if(!file_exists($cache_file)) {
$cache_fwrite = true;
} else {
if($cache_time > 0) {
$filetime = filemtime($cache_file);
if($filetime && $filetime < (G5_SERVER_TIME - 3600 * $cache_time)) {
@unlink($cache_file);
$cache_fwrite = true;
}
}
if(!$cache_fwrite)
include($cache_file);
}
}
if(!G5_USE_CACHE || $cache_fwrite) {
$list = array();
$sql = " select * from {$g5['board_table']} where bo_table = '{$bo_table}' ";
$board = sql_fetch($sql);
$bo_subject = get_text($board['bo_subject']);
$arr_notice = explode(",", 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) ";
}
$tmp_write_table = $g5['write_prefix'] . $bo_table; // 게시판 테이블 전체이름
$sql = " select * from {$tmp_write_table} where wr_is_comment = 0 $sql_search order by wr_num limit 0, {$rows} ";
$result = sql_query($sql);
$tmp_i = 0;
$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_url, $subject_len);
$list[$i][is_notice] = true;
$list[$i][board] = $board[bo_table];
$list[$i][href] = G5_BBS_URL.substr($list[$i][href],1,strlen($list[$i][href]));
$i++;
$tmp_i++;
}
while ($row = sql_fetch_array($result)){
if($tmp_i >= $rows){
break;
}
$list[$i] = get_list($row, $board, $latest_skin_url, $subject_len);
$list[$i][board] = $board[bo_table];
$list[$i][href] = G5_BBS_URL.substr($list[$i][href],1,strlen($list[$i][href]));
$i++;
$tmp_i++;
}
if($cache_fwrite) {
$handle = fopen($cache_file, 'w');
$cache_content = "<?php\nif (!defined('_GNUBOARD_')) exit;\n\$bo_subject='".$bo_subject."';\n\$list=".var_export($list, true)."?>";
fwrite($handle, $cache_content);
fclose($handle);
}
}
ob_start();
include $latest_skin_path.'/latest.skin.php';
$content = ob_get_contents();
ob_end_clean();
return $content;
}
[/code]
댓글 26개
감사합니다.
이팁을 그누보드 5.3버전에 적용하니 불러오기는 제대로 불러오는데,
링크가 좀 이상합니다.
혹시 제대로 나오게 하는 방법이 없을까요?
링크가
http://도메인명/bbs/board.php?bo_table=free&wr_id=8
이렇게 걸려야 하는데,
아래처럼 걸립니다.
http://도메인명/bbsttp://도메인명/bbs/board.php?bo_table=free&wr_id=8
// $list[$i][href] = G5_BBS_URL.substr($list[$i][href],1,strlen($list[$i][href]));
덕분에 해결되었습니다.
감사합니다.
게시판 목록
그누보드5 팁자료실
| 번호 | 제목 | 글쓴이 | 날짜 | 조회 |
|---|---|---|---|---|
| 공지 | 3년 전 | 4402 | ||
| 2694 | 2개월 전 | 188 | ||
| 2693 | 2개월 전 | 148 | ||
| 2692 | 2개월 전 | 158 | ||
| 2691 | 2개월 전 | 174 | ||
| 2690 | 2개월 전 | 326 | ||
| 2689 | 2개월 전 | 233 | ||
| 2688 |
|
2개월 전 | 441 | |
| 2687 | 2개월 전 | 292 | ||
| 2686 |
선택과집중
|
2개월 전 | 329 | |
| 2685 | 2개월 전 | 291 | ||
| 2684 | 2개월 전 | 346 | ||
| 2683 | 2개월 전 | 481 | ||
| 2682 | 2개월 전 | 276 | ||
| 2681 | 2개월 전 | 302 | ||
| 2680 |
선택과집중
|
2개월 전 | 278 | |
| 2679 | 2개월 전 | 330 | ||
| 2678 |
|
3개월 전 | 429 | |
| 2677 |
|
3개월 전 | 502 | |
| 2676 | 3개월 전 | 326 | ||
| 2675 | 3개월 전 | 304 | ||
| 2674 |
선택과집중
|
3개월 전 | 480 | |
| 2673 |
|
3개월 전 | 322 | |
| 2672 | 3개월 전 | 335 | ||
| 2671 | 3개월 전 | 284 | ||
| 2670 | 3개월 전 | 260 | ||
| 2669 | 3개월 전 | 374 | ||
| 2668 | 3개월 전 | 289 | ||
| 2667 |
선택과집중
|
3개월 전 | 484 | |
| 2666 |
선택과집중
|
3개월 전 | 470 | |
| 2665 |
선택과집중
|
3개월 전 | 404 |
댓글 작성
댓글을 작성하시려면 로그인이 필요합니다.
로그인하기