notice() : latest() 함수의 일반화 > 그누4 팁자료실

그누4 팁자료실

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

notice() : latest() 함수의 일반화 정보

notice() : latest() 함수의 일반화

첨부파일

notice.lib.utf8.zip (1.0K) 14회 다운로드 2010-05-16 02:13:35
notice.lib.euckr.zip (996byte) 8회 다운로드 2010-05-16 02:13:35

본문

공지 스킨에 다양한 정렬 필드에 의한 추출을 원하시는 분들에게 도움이 되는 함수를 소개합니다.

공지 사항 추출에 게시판별로 설정된 정렬 필드가 그대로 적용될 수 있도록 하거나 또는 임의 지정 하려면 'notice.lib.php'를 lib 디렉터리에 설치하고 사용할 프로그램에서 include한 후 여기에 정의된 notice() 함수를 이용하면 됩니다.

notice() 함수의 특성

- 테이블에 설정된 정렬 필드(bo_sort_field) 순서에 의한 글 추출
- 임의 지정 정렬 필드 순서에 의한 글 추출 (예: wr_num, wr_datetime, wr_hit, wr_last 등) (adm/board_form.php 참고)
- latest() 함수의 일반화. 다양한 정렬 필드 반영
- notice() 함수 호출시 $sort_option 값을 'wr_num'으로 지정하면 latest()와 동일
- latest()와 skin 경로를 공유함으로써 latest 스킨들을 그대로 이용함

함수의 호출 (예)

- notice('basic', 'intro_bbs', 10, 40) : 게시판에 설정된 정렬 필드에 따라 글 추출
- notice('basic', 'notice_bbs', 10, 40, 'wr_num') : latest('basic', 'notice_bbs', 10, 40)과 동일

설치 관련

- 설치 위치: lib 디렉터리
- 적용 대상: 그누보드 4.31, 4.32

함수의 정의 (notice.lib.php)

function notice($skin_dir="", $bo_table, $rows=10, $subject_len=40, $sort_option="", $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);

    // 정렬 필드
    if ($sort_option)
        $sql_order = "order by $sort_option";
    else if ($board[bo_sort_field])
        $sql_order = " order by $board[bo_sort_field]";
    else
        $sql_order = "order by wr_num";

    // 정렬 필드에 의한 글 추출
    $tmp_write_table = $g4['write_prefix'] . $bo_table; // 게시판 테이블 전체이름
    $sql = " select * from $tmp_write_table where wr_is_comment = 0 $sql_order limit 0, $rows ";

    $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
  • 복사

댓글 4개

저도 공지사항과 같은 특수한 경우를 위한 함수를 따로 만들어서 쓰는 편인데요...
공지사항에서 공지 옵션이 있는 경우도 들어가면 더 좋을 듯 싶군요...
저의 경우에는 가중치를 넣는 경우도 있다는 ^^
© SIRSOFT
현재 페이지 제일 처음으로