[최신글] 랜덤, 카테고리, 원글 아래 답글 등 (2009/05/13 수정) > 그누4 팁자료실

그누4 팁자료실

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

[최신글] 랜덤, 카테고리, 원글 아래 답글 등 (2009/05/13 수정) 정보

[최신글] 랜덤, 카테고리, 원글 아래 답글 등 (2009/05/13 수정)

본문

그누보드 / extend / hp.latest.php  로 파일을 만들어서 업로드합니다.
1. 최신글 랜덤으로 보이기
    랜덤 추출 함수  rand()  활용
   사용법 : <?=latest_rand("최신글스킨", "게시판이름", 게시물수, 제목글자수");?>
2. 카테고리로 최신글 보이기  # 2008-07-03 추가 , 2009-05-13 수정
   사용법 : <?=latest_category("최신글스킨", "게시판이름", 게시물수, 제목글자수, "옵션", "카테고리이름");?>
3. 답글이 원본글 밑에 붙는 방식
   사용법 : <?=latest_re("최신글스킨", "게시판이름", 게시물수, 제목글자수);?>
4. 작성일자로 최신글 추출  # 2008-07-03 추가
   사용법 : <?=latest_datetime("최신글스킨", "게시판이름", 게시물수, 제목글자수);?>


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

/*
1. 최신글 랜덤으로 보이기
   랜덤 추출 함수  rand()  활용
   사용법 : <?=latest_rand("최신글스킨", "게시판이름", 게시물수, 제목글자수);?>
*/
// 최신글 랜덤 추출
function latest_rand($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; // 게시판 테이블 전체이름
    $sql = " select * from $tmp_write_table where wr_is_comment = 0 order by rand() desc 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);
   
    ob_start();
    include "$latest_skin_path/latest.skin.php";
    $content = ob_get_contents();
    ob_end_clean();

    return $content;
}

/*
2. 카테고리(분류)만 추출 최신글 보이기  ( 2009-05-13 수정 )
  사용법 : <?=latest_category("최신글스킨", "게시판이름", 게시물수, 제목글자수, "옵션", "카테고리이름");?>

skin/latest/스킨/latest.skin.php  을 수정합니다.
일반 최신게시물    :  {$list[$i]['href']}   를   {$list[$i]['href']}&sca={$category}  로 수정
갤러리 최신게시물 :  bo_table=$bo_table  를   bo_table=$bo_table&sca=$category  로 수정
*/
// 최신글 카테고리 데이타만 추출
function latest_category ($skin_dir="", $bo_table, $rows=10, $subject_len=40, $options="", $category="") {
    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; // 게시판 테이블 전체이름
    $sql = " select * from $tmp_write_table where ca_name = '$category' 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);
   
    ob_start();
    include "$latest_skin_path/latest.skin.php";
    $content = ob_get_contents();
    ob_end_clean();

    return $content;
}

/*
3. 답글이 원본글 밑에 붙는 방식
   사용법 : <?=latest_re("최신글스킨", "게시판이름", 게시물수, 제목글자수);?>
*/
// 최신글 추출 ## 답글이 원본글 밑에 붙는 방식
function latest_re($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; // 게시판 테이블 전체이름
    $sql = " select * from $tmp_write_table where wr_is_comment = 0 order by wr_num asc, wr_id asc 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);
   
    ob_start();
    include "$latest_skin_path/latest.skin.php";
    $content = ob_get_contents();
    ob_end_clean();

    return $content;
}

/*
4. 작성일자로 최신글 추출
   사용법 : <?=latest_datetime("최신글스킨", "게시판이름", 게시물수, 제목글자수);?>
*/
// 작성일자로 최신글 추출
function latest_datetime($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; // 게시판 테이블 전체이름
    //$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_datetime desc 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);
   
    ob_start();
    include "$latest_skin_path/latest.skin.php";
    $content = ob_get_contents();
    ob_end_clean();

    return $content;
}
?>



rand

(PHP 3, PHP 4 , PHP 5)
rand -- 정수형의 난수를 생성합니다.
설명
int rand ( [int min, int max])

부수적인 min, max 인수 없이 호출하면, rand()는 0과 RAND_MAX 사이의 임의의 난수를 반환합니다. 예를 들어, 5와 15(포함) 사이의 난수를 얻으려면, rand (5, 15)로 사용합니다.



참고자료 
http://kr.php.net/manual/kr/function.rand.php 
http://sir.co.kr/bbs/board.php?bo_table=g4_qa&wr_id=84024 
http://sir.co.kr/bbs/board.php?bo_table=g4_skin&wr_id=84600 

추천
14

댓글 22개

이렇게 멋진걸 왜 지금 봤을까. 어떻게 검색할때마다 새로운게 나오는지?-_-;
그누는 마르지않는 샘물인가..ㅋㅋ
해피정님 늦었지만 정말 감사합니다. 늦은 추천 한방도 받으세욧 !
정말 훌륭하십니다 그리고 너무나 감사합니다.
저같은 초보자한테는 무슨말인지 잘은 모르지만 그래도 날밤 세우며 끙끙 알아가며 공부하게 너무나 좋은 자료이네요.
감사합니다 ^^
아....... 너무너무 감사합니다. 아주 심플하게 완벽하게 한방에 끝나버렸네요. 스킨도 상관없고 이미지가 있던 없던 상관없고 완벽합니다. ^^
이거 되나요???
 [이벤트] (22)                            [06-18]
[이벤트] 레알 이벤트 시… (12)  [05-10]
[이벤트] (15)                          [06-17]
[이벤트] (6) 


이런 식으로 나오는데요... 머가 잘못되었을까요?
전체 3,309 |RSS
그누4 팁자료실 내용 검색

회원로그인

(주)에스아이알소프트 / 대표:홍석명 / (06211) 서울특별시 강남구 역삼동 707-34 한신인터밸리24 서관 1402호 / E-Mail: admin@sir.kr
사업자등록번호: 217-81-36347 / 통신판매업신고번호:2014-서울강남-02098호 / 개인정보보호책임자:김민섭(minsup@sir.kr)
© SIRSOFT