최근게시물에 2개이상의 게시판 을 최근순서대로 불러올때.. 정보
최근게시물에 2개이상의 게시판 을 최근순서대로 불러올때..본문
허접이라.. 틀린부분이나 더 좋은 방법 있으면 거침없이 의견 주세요~
메인 페이지 최근 게시물에, 2개 이상의 게시판에서, 가장 최근 게시물을 불러올때
lib/latest.lib.php 를 수정합니다.
아래 소스를 복사해서 붙혀넣으시면 되겠습니다..
function latest2($skin_dir="", $bo_table1,$bo_table2,$bo_table3,$bo_table4, $rows=10, $subject_len=40, $options="")
//$bo_table1,$bo_table2,$bo_table3,$bo_table4, 는 몇개 불러올지.. 맘대로 늘리시면 됩니다.
{
global $g4;
if ($skin_dir)
$latest_skin_path = "$g4[path]/skin/latest/$skin_dir";
else
$latest_skin_path = "$g4[path]/skin/latest/basic";
$sql_common = " from $g4[board_new_table] a, $g4[board_table] b
where a.bo_table = b.bo_table and a.bo_table in('$bo_table1', '$bo_table2', '$bo_table3', '$bo_table4') ";
// '$bo_table1', '$bo_table2', '$bo_table3', '$bo_table4' 역시 몇개 불러올건지.. 위에 맞게 수정하시면 되겠습니다.
$sql_common .= " and a.wr_id = a.wr_parent ";
// 요건 원본글만 불러온다는 말이죠..
$sql_order = " order by a.bn_id desc ";
// 요건 new테이블에 저장된 최근 순서대로..
$sql_select = " b.gr_id, a.bo_table, a.wr_id, a.wr_parent, a.bn_datetime, b.bo_subject ";
$list = array();
$sql = " select $sql_select, b.bo_subject
$sql_common
$sql_order
limit $rows ";
$result = sql_query($sql);
for ($i=0; $row=sql_fetch_array($result); $i++)
{
$tmp_write_table = $g4[write_prefix] . $row[bo_table];
$comment = "";
$comment_link = "";
$row2 = sql_fetch(" select * from $tmp_write_table where wr_id = '$row[wr_id]' ");
$list[$i] = $row2;
$list[$i] = get_list($row2, $board, $latest_skin_path, $subject_len);
$bo_herf[$i] = $row[bo_table];
$bo_name[$i] = $row[bo_subject];
$list[$i][wr_date] = $row2[wr_datetime];
}
ob_start();
include "$latest_skin_path/latest.skin.php";
$content = ob_get_contents();
ob_end_clean();
return $content;
}
를 추가합니다.
latest.skin.php 에서..
$bo_herf[$i] 는 게시판경로에 쓰이고요,
$bo_name[$i] 는 제목 앞에 넣어주면, 어느 게시판인지 알수 있겟쬬?
오달수님 팁 :
$list[$i][icon_new] = "";
if($list[$i][wr_date] >= date("Y-m-d H:i:s", $g4[server_time] -(3600*24*2)))
$list[$i][icon_new] = "<img src='$latest_skin_path/img/icon_new.gif' align='absmiddle'>";
도 넣어주면 new 아이콘도 표시 됩니다.
<?=latest2("index", 게시판1,게시판2,게시판3,게시판4, 5, 40);?><?=latest2("index", 게시판1,게시판2,게시판3,게시판4, 5, 40);?>
로 불러오면 되겠습니다..
new.php 배껴서 급조하게 만든;;
간단하네요..
흠 EXPLAIN 해본 결과 인덱스 잘 타긴 하는거 같습니다.
참 쉽죠잉?;;
1차 수정 : new 아이콘 표시와, 필요없는것좀 지웠습니다.^^;
4