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

가져오고 싶은 게시판 글만 모아서 최신순으로!

· 13년 전 · 1858 · 3
가져오고 싶은 게시판 글만 모아서 최신순으로!

<?
if (!defined('_GNUBOARD_')) exit;

// 최신글 추출
function latest($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();

$bo_table_exp = explode(",",$bo_table);
$bo_table_exp_cnt = count($bo_table_exp); // 추가된 코드

//$sql = " select * from $g4[board_table] where bo_table = '$bo_table'"; 원본소스
if(count($bo_table_exp)==1) $sql = " select * from $g4[board_table] where bo_table = '$bo_table'";
if(count($bo_table_exp)==1) $board = sql_fetch($sql);
if(count($bo_table_exp)==1) $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 ";
// 위의 코드 보다 속도가 빠름

//$sql = " select * from $tmp_write_table where wr_is_comment = 0 order by wr_num limit 0, $rows "; 원본소스
if(count($bo_table_exp)==1){
$sql = " select * from $tmp_write_table where wr_is_comment = 0 order by wr_num limit 0, $rows ";
}else{
$new_sql = " SELECT * FROM `g4_board_new` WHERE ";
for($n=0; $n<$bo_table_exp_cnt; $n++){
$new_sql = $new_sql." `bo_table` = '".$bo_table_exp[$n]."' ";
if($n<$bo_table_exp_cnt-1){$new_sql = $new_sql." OR "; };
}
$new_sql = $new_sql." ORDER BY `bn_datetime` DESC LIMIT 0, $rows ";
$new_result = sql_query($new_sql);

for ($i=0; $new_row = sql_fetch_array($new_result); $i++){
$sql = $sql." SELECT * FROM `".$g4['write_prefix'].$new_row['bo_table']."` WHERE `wr_id` = ".$new_row['wr_id'] ;
if($i<$rows-1) $sql = $sql." UNION ALL ";
$new_board[] = $new_row['bo_table'];
}
}

//explain($sql);
$result = sql_query($sql);

if(count($bo_table_exp)==1){
for ($i=0; $row = sql_fetch_array($result); $i++){
$list[$i] = get_list($row, $board, $latest_skin_path, $subject_len);
}
}else{
for ($i=0; $row = sql_fetch_array($result); $i++){
$board['bo_table'] = $new_board[$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;
}
?>

메인화면에
<?=latest("wn_list_all", "portfolio,wallpaper,freeboard,playground", 15, 35);?>
이렇게 입력을 했구요.. 가운데 들어있는 게시판에서만 리스트를 가지고 옵니다...
latest.lib.php만 수정해서 성공한것 같은데요...
이걸 좀 더 그누보드 스럽게 코딩 할 수 있을까요?

댓글 작성

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

로그인하기

댓글 3개

그누보드스러운 코딩이 아니라 mysql 스러운 코딩이 필요하겠군요
그리고 단일 게시판을 추출하는 latest는 그대로 두고 latest_multi() 함수를 하나 더 만들어 버리면
if(count.. ==1) 이런 부분은 필요없어지고 코드가 훨씬 간단해질텐데 이 부분이 맘에 안드네요 ㅎㅎ
SELECT * FROM `g4_board_new` WHERE bo_table IN ('portfolio','wallpaper','freeboard','playground') ORDER BY `bn_datetime` DESC LIMIT 0, $rows
new 테이블에서 추출해오는 코드는 이런 방법을 사용하시고, union all 같은 것은 필요없습니다
위 코드처럼 값을 가져와서 for문으로 해당 테이블에서 게시글 추출하여 $list에 바로 저장하면 됩니다
최신글이니까 wr_subject 와 날짜 등 필요한 몇개만 추출해서 만들면 되겠습니다
bbs/new.php 코드를 참고해서 만드세요

get_list()는 게시물 마다 $board 값이 필요하니 이것을 이용하지말고 리스트는 직접 만들되
이미지가 필요하면 get_file()함수로 가져와서 만드는 것이 좋겠습니다
균이님 감사합니다.

게시글 목록

번호 제목
284438
284437
284435
284430
284420
284417
284409
284401
284399
284397
284380
284378
284371
284370
284366
284364
284360
284357
284355
284354