최신글에서 공지 글 먼저, 일반 글 나중

관련 글을 찾다 찾다,  힘들어서 만들어봤습니다.

짜맞추고, 편법쓰고, 머리굴리고,.  만들자 마자 기분좋아서 올리는거라,

소스 정리가 약간 덜 되있는편입니다.

공지글을 먼저 select시켜서 올리고, 그 공지글의 갯수를 rows에서 빼서,

뺀갯수만큼 일반글이 추출되도록 다시 select 시켜서..  편법을 좀 썼습니다.

첨부파일

latest.lib.php (1.9 KB) 217회 2009-06-02 10:04
latest.skin.php (2.8 KB) 69회 2009-06-02 10:04
|

댓글 5개

찾고있던 것입니다..^^ 감사합니다.
제가 잘못한건가염 .왜 적용이 안될까염..똑같아요 테스트해도 ㅠ.ㅠ 경로에 업로드시켰는뎀..
글구 lib꺼는 추가로 넣었는뎀..왜 안되졍 흑흑
latest.lib.php 소스 수정을 봤습니다.
$list 에 데이타 들어가게 했어요.
============================================================
<?
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();

$sql = " select * from $g4[board_table] where bo_table = '$bo_table'";
$board = sql_fetch($sql);

$tmp_write_table = $g4['write_prefix'] . $bo_table; // 게시판 테이블 전체이름

$arr_notice = split("\n", trim($board[bo_notice]));
$sql_notice = "";
for($i=0;$i<count($arr_notice);$i++){
if($i != 0){
$sql_notice .= " or ";
}
$arr_notice[$i] = trim($arr_notice[$i]);
if (strlen($arr_notice[$i]) > 0) $sql_notice .= "wr_id=$arr_notice[$i]";
}
if (strlen($sql_notice) > 0) $sql_notice = " and ( " . $sql_notice . ") ";

//$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 $sql_notice order by wr_num limit 0, $rows ";
//explain($sql);
$result = sql_query($sql);
for ($i=0; $row = sql_fetch_array($result); $i++)
$list[$i] = get_list($row, $board, $latest_skin_path, $subject_len);

$count = " select count(*) as cnt from $tmp_write_table where wr_is_comment = 0 $sql_notice order by wr_num limit 0, $rows ";
$cnt = sql_fetch($count);
$total = $rows - $cnt[cnt];
$sql_notice = "";
for($i=0;$i<count($arr_notice);$i++){
if($i != 0){
$sql_notice .= " and ";
}

$arr_notice[$i] = trim($arr_notice[$i]);
if (strlen($arr_notice[$i]) > 0) $sql_notice .= "wr_id != $arr_notice[$i]";
}
if (strlen($sql_notice) > 0) $sql_notice = " and ( " . $sql_notice . ") ";

$sql_common = " select * from $tmp_write_table where wr_is_comment = 0 $sql_notice order by wr_num limit 0, $total ";
$result = sql_query($sql_common);
for ($i=0; $row = sql_fetch_array($result); $i++)
$list[($i+$cnt[cnt])] = 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;
}
?>
/lib/latest.lib.php 공지 최신글 추출하기

// 공지 최신글 추출
function latest_notice($skin_dir="", $bo_table, $rows=5, $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();
$i = 0;
$sql = " select * from $g4[board_table] where bo_table = '$bo_table'";
$board = sql_fetch($sql);

$tmp_write_table = $g4['write_prefix'] . $bo_table; // 게시판 테이블 전체이름

$arr_notice = split("\n", trim($board[bo_notice]));
for ($k=0; $k<$rows; $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, $board_skin_path, $subject_len);
$list[$i][is_notice] = true;

$i++;
}

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

return $content;
}
한번해봐야겠네요....몇일째 찾아헤매고있음...ㅠㅠ
댓글을 작성하시려면 로그인이 필요합니다. 로그인

그누4 팁자료실

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

+
제목 글쓴이 날짜 조회
16년 전 조회 2,133
16년 전 조회 4,403
16년 전 조회 4,695
16년 전 조회 4,203
16년 전 조회 2,523
16년 전 조회 5,595
16년 전 조회 2,514
16년 전 조회 2,966
16년 전 조회 4,772
16년 전 조회 3,735
16년 전 조회 2,340
16년 전 조회 4,632
16년 전 조회 3,206
16년 전 조회 2.1만
16년 전 조회 4,160
16년 전 조회 5,202
16년 전 조회 3,303
16년 전 조회 4,908
16년 전 조회 5,156
16년 전 조회 4,681
🐛 버그신고