메인 최신글에서 공지사항 제거 후 출력하는 방법 채택완료
latest.lib.php 에서 공지사항을 제외하도록 수정하였는데요
문제가 공지사항글이 단 한개라도 없는 게시판은 아예 글 출력이 안되네요.
$sql = " select * from {$tmp_write_table} where wr_is_comment = 0 and not wr_id in ( {$board['bo_notice']}) order by wr_num limit 0, {$rows} "; // 공지사항 제외
조언좀 부탁드립니다.
아래는 전체 코드입니다.
</p>
<p><?php</p>
<p>if (!defined('_GNUBOARD_')) exit;</p>
<p>@include_once(G5_LIB_PATH.'/thumbnail.lib.php');</p>
<p> </p>
<p>// 최신글 추출</p>
<p>// $cache_time 캐시 갱신시간</p>
<p>function latest($skin_dir='', $bo_table, $rows=10, $subject_len=40, $cache_time=1, $options='')</p>
<p>{</p>
<p> global $g5;</p>
<p> </p>
<p> if (!$skin_dir) $skin_dir = 'basic';</p>
<p> </p>
<p> $time_unit = 3600; // 1시간으로 고정</p>
<p> </p>
<p> if(preg_match('#^theme/(.+)$#', $skin_dir, $match)) {</p>
<p> if (G5_IS_MOBILE) {</p>
<p> $latest_skin_path = G5_THEME_MOBILE_PATH.'/'.G5_SKIN_DIR.'/latest/'.$match[1];</p>
<p> if(!is_dir($latest_skin_path))</p>
<p> $latest_skin_path = G5_THEME_PATH.'/'.G5_SKIN_DIR.'/latest/'.$match[1];</p>
<p> $latest_skin_url = str_replace(G5_PATH, G5_URL, $latest_skin_path);</p>
<p> } else {</p>
<p> $latest_skin_path = G5_THEME_PATH.'/'.G5_SKIN_DIR.'/latest/'.$match[1];</p>
<p> $latest_skin_url = str_replace(G5_PATH, G5_URL, $latest_skin_path);</p>
<p> }</p>
<p> $skin_dir = $match[1];</p>
<p> } else {</p>
<p> if(G5_IS_MOBILE) {</p>
<p> $latest_skin_path = G5_MOBILE_PATH.'/'.G5_SKIN_DIR.'/latest/'.$skin_dir;</p>
<p> $latest_skin_url = G5_MOBILE_URL.'/'.G5_SKIN_DIR.'/latest/'.$skin_dir;</p>
<p> } else {</p>
<p> $latest_skin_path = G5_SKIN_PATH.'/latest/'.$skin_dir;</p>
<p> $latest_skin_url = G5_SKIN_URL.'/latest/'.$skin_dir;</p>
<p> }</p>
<p> }</p>
<p> </p>
<p> $caches = false;</p>
<p> </p>
<p> if(G5_USE_CACHE) {</p>
<p> $cache_file_name = "latest-{$bo_table}-{$skin_dir}-{$rows}-{$subject_len}-".g5_cache_secret_key();</p>
<p> $caches = g5_get_cache($cache_file_name, (int) $time_unit * (int) $cache_time);</p>
<p> $cache_list = isset($caches['list']) ? $caches['list'] : array();</p>
<p> g5_latest_cache_data($bo_table, $cache_list);</p>
<p> }</p>
<p> </p>
<p> if( $caches === false ){</p>
<p> </p>
<p> $list = array();</p>
<p> </p>
<p> $board = get_board_db($bo_table, true);</p>
<p> </p>
<p> if( ! $board ){</p>
<p> return '';</p>
<p> }</p>
<p> </p>
<p> $bo_subject = get_text($board['bo_subject']);</p>
<p> </p>
<p> $tmp_write_table = $g5['write_prefix'] . $bo_table; // 게시판 테이블 전체이름</p>
<p> $bo_notice = $board['bo_notice'];</p>
<p> //$sql = " select * from {$tmp_write_table} where wr_is_comment = 0 order by wr_num limit 0, {$rows} ";</p>
<p> $sql = " select * from {$tmp_write_table} where wr_is_comment = 0 and not wr_id in ( {$board['bo_notice']}) order by wr_num limit 0, {$rows} "; // 공지사항 제외</p>
<p> //$sql = " select * from {$tmp_write_table} where wr_is_comment = 0 and not wr_id in ( {$board['bo_notice']}) order by wr_num limit 0, {$rows} ";</p>
<p> </p>
<p> $result = sql_query($sql);</p>
<p> for ($i=0; $row = sql_fetch_array($result); $i++) {</p>
<p> try {</p>
<p> unset($row['wr_password']); //패스워드 저장 안함( 아예 삭제 )</p>
<p> } catch (Exception $e) {</p>
<p> }</p>
<p> $row['wr_email'] = ''; //이메일 저장 안함</p>
<p> if (strstr($row['wr_option'], 'secret')){ // 비밀글일 경우 내용, 링크, 파일 저장 안함</p>
<p> $row['wr_content'] = $row['wr_link1'] = $row['wr_link2'] = '';</p>
<p> $row['file'] = array('count'=>0);</p>
<p> }</p>
<p> $list[$i] = get_list($row, $board, $latest_skin_url, $subject_len);</p>
<p> </p>
<p> $list[$i]['first_file_thumb'] = (isset($row['wr_file']) && $row['wr_file']) ? get_board_file_db($bo_table, $row['wr_id'], 'bf_file, bf_content', "and bf_type in (1, 2, 3, 18) ", true) : array('bf_file'=>'', 'bf_content'=>'');</p>
<p> $list[$i]['bo_table'] = $bo_table;</p>
<p> // 썸네일 추가</p>
<p> if($options && is_string($options)) {</p>
<p> $options_arr = explode(',', $options);</p>
<p> $thumb_width = $options_arr[0];</p>
<p> $thumb_height = $options_arr[1];</p>
<p> $thumb = get_list_thumbnail($bo_table, $row['wr_id'], $thumb_width, $thumb_height, false, true);</p>
<p> // 이미지 썸네일</p>
<p> if($thumb['src']) {</p>
<p> $img_content = '<img src="'.$thumb['src'].'" alt="'.$thumb['alt'].'" width="'.$thumb_width.'" height="'.$thumb_height.'">';</p>
<p> $list[$i]['img_thumbnail'] = '<a href="'.$list[$i]['href'].'" class="lt_img">'.$img_content.'</a>';</p>
<p> // } else {</p>
<p> // $img_content = '<img src="'. G5_IMG_URL.'/no_img.png'.'" alt="'.$thumb['alt'].'" width="'.$thumb_width.'" height="'.$thumb_height.'" class="no_img">';</p>
<p> }</p>
<p> }</p>
<p> </p>
<p> if(! isset($list[$i]['icon_file'])) $list[$i]['icon_file'] = '';</p>
<p> }</p>
<p> g5_latest_cache_data($bo_table, $list);</p>
<p> </p>
<p> if(G5_USE_CACHE) {</p>
<p> </p>
<p> $caches = array(</p>
<p> 'list' => $list,</p>
<p> 'bo_subject' => sql_escape_string($bo_subject),</p>
<p> );</p>
<p> </p>
<p> g5_set_cache($cache_file_name, $caches, (int) $time_unit * (int) $cache_time);</p>
<p> }</p>
<p> } else {</p>
<p> $list = $cache_list;</p>
<p> $bo_subject = (is_array($caches) && isset($caches['bo_subject'])) ? $caches['bo_subject'] : '';</p>
<p> }</p>
<p> </p>
<p> ob_start();</p>
<p> include $latest_skin_path.'/latest.skin.php';</p>
<p> $content = ob_get_contents();</p>
<p> ob_end_clean();</p>
<p> </p>
<p> return $content;</p>
<p>}</p>
<p>
답변 3개
$sql = " select * from {$tmp_write_table} where wr_is_comment = 0 and not wr_id in ( {$board['bo_notice']}) order by wr_num limit 0, {$rows} "; // 공지사항 제외
부분을
if($board['bo_notice']) {
$sql = " select * from {$tmp_write_table} where wr_is_comment = 0 and not wr_id in ( {$board['bo_notice']}) order by wr_num limit 0, {$rows} "; // 공지사항 제외
}else{
$sql = " select * from {$tmp_write_table} where wr_is_comment = 0 order by wr_num limit 0, {$rows} "; // 공지사항 제외
}
로 간단하게 있을때랑 없을때랑 나눠보세요.
댓글을 작성하려면 로그인이 필요합니다.
댓글을 작성하려면 로그인이 필요합니다.
</p>
<pre>
<code>$sql = " select * from {$tmp_write_table} where wr_is_comment = 0 and not wr_id in ( {$board['bo_notice']}) order by wr_num limit 0, {$rows} "; // 공지사항 제외</code></pre>
<p><code>
=>
</code></p>
<p><code> $sql = " select * from {$tmp_write_table} where wr_is_comment = 0";
if ($bo_notice) {
$sql .= " and not wr_id in ({$bo_notice})";
}
$sql .= " order by wr_num limit 0, {$rows} "; // 공지사항 제외</code></p>
<p><code>
댓글을 작성하려면 로그인이 필요합니다.
답변을 작성하려면 로그인이 필요합니다.
로그인