해피정님의 카테고리별 최신글을 랜덤으로 출력하고 싶어요. > 그누4 질문답변

그누4 질문답변

그누보드4 관련 질문은 QA 로 이전됩니다. QA 그누보드4 바로가기
기존 게시물은 열람만 가능합니다.

해피정님의 카테고리별 최신글을 랜덤으로 출력하고 싶어요. 정보

해피정님의 카테고리별 최신글을 랜덤으로 출력하고 싶어요.

본문

오류가 나는곳의 주소를 알려주시면 더 빠르고 정확하게 답변 받을 수 있습니다.

오류 주소 :


http://www.sir.co.kr/bbs/board.php?bo_table=g4_tiptech&wr_id=11019&sca=&sfl=wr_subject%7C%7Cwr_content&stx=%B7%A3%B4%FD+%C3%D6%BD%C5%B1%DB&sop=and

해피정님 소스구요.


그누보드 / 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']}&amp;sca={$category}  로 수정
갤러리 최신게시물 :  bo_table=$bo_table  를   bo_table=$bo_table&amp;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;
}
?>





해피정님 팁 덕분에 카테고리별 출력 잘 사용중인데요.


카테고리별 랜덤 기능을 사용하고 싶어졌는데.. 알려주세요 ㅠ_ㅠ;
  • 복사

댓글 전체

© SIRSOFT
현재 페이지 제일 처음으로