최신글 카테고리별로 불러오기+카테고리2개이상 불러오기 > 그누보드5 팁자료실

그누보드5 팁자료실

최신글 카테고리별로 불러오기+카테고리2개이상 불러오기 정보

최신글 카테고리별로 불러오기+카테고리2개이상 불러오기

본문

왕계란님 팁 이용해서 수정했습니다(http://sir.kr/g5_tip/4129?sfl=wr_subject%7C%7Cwr_content&stx=%EC%B5%9C%EC%8B%A0%EA%B8%80+%EC%B9%B4%ED%85%8C%EA%B3%A0%EB%A6%AC)

<?=latest("theme/basic", "qa", 5, 25)?>
이게 기본적인 최신글 함수 사용법인데요,
<?=latest("theme/basic", "qa|답변", 5, 25)?>
이런 식으로 게시판 아이디 다음에 '|특정 카테고리'를 붙여 넣습니다.
그러면 뿌리는 부분에서는 끝이 났습니다.

<?=latest("theme/basic", "qa|답변,질문", 5, 25)?>
카테고리 2개 부를때는 컴마로 구문하시면 됩니다
소스가 너무 초급이고 지저분한데 깔끔하게 정리가능하시면
해주시면 감사할거같아요


lib > latest.lib.php

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

// 최신글 추출
// $cache_time 캐시 갱신시간
function latest($skin_dir='', $bo_table, $rows=10, $subject_len=40, $cache_time=1, $options='')
{
    global $g5;

    list($bo_table, $category) = explode("|", $bo_table);
    if($category) {
    $cateArray = array();
    $cateArray = explode(",", $category);
    for($i=0;$i<count($cateArray);$i++){
    if($i==0)
    $where = " AND ca_name = '".$cateArray[$i]."' ";
    else
    $where .= " OR ca_name = '".$cateArray[$i]."' ";
    }
   
    }
   
    if (!$skin_dir) $skin_dir = 'basic';
   
    if(preg_match('#^theme/(.+)$#', $skin_dir, $match)) {
        if (G5_IS_MOBILE) {
            $latest_skin_path = G5_THEME_MOBILE_PATH.'/'.G5_SKIN_DIR.'/latest/'.$match[1];
            if(!is_dir($latest_skin_path))
                $latest_skin_path = G5_THEME_PATH.'/'.G5_SKIN_DIR.'/latest/'.$match[1];
            $latest_skin_url = str_replace(G5_PATH, G5_URL, $latest_skin_path);
        } else {
            $latest_skin_path = G5_THEME_PATH.'/'.G5_SKIN_DIR.'/latest/'.$match[1];
            $latest_skin_url = str_replace(G5_PATH, G5_URL, $latest_skin_path);
        }
        $skin_dir = $match[1];
    } else {
        if(G5_IS_MOBILE) {
            $latest_skin_path = G5_MOBILE_PATH.'/'.G5_SKIN_DIR.'/latest/'.$skin_dir;
            $latest_skin_url  = G5_MOBILE_URL.'/'.G5_SKIN_DIR.'/latest/'.$skin_dir;
        } else {
            $latest_skin_path = G5_SKIN_PATH.'/latest/'.$skin_dir;
            $latest_skin_url  = G5_SKIN_URL.'/latest/'.$skin_dir;
        }
    }
   
    $cache_fwrite = false;
    if(G5_USE_CACHE) {
    if($category){
    $cache_file = G5_DATA_PATH."/cache/latest-{$bo_table}-{$category}-{$skin_dir}-{$rows}-{$subject_len}.php";
    }else{
    $cache_file = G5_DATA_PATH."/cache/latest-{$bo_table}-{$skin_dir}-{$rows}-{$subject_len}.php";
    }
        if(!file_exists($cache_file)) {
            $cache_fwrite = true;
        } else {
            if($cache_time > 0) {
                $filetime = filemtime($cache_file);
                if($filetime && $filetime < (G5_SERVER_TIME - 3600 * $cache_time)) {
                    @unlink($cache_file);
                    $cache_fwrite = true;
                }
            }

            if(!$cache_fwrite)
                include($cache_file);
        }
    }

    if(!G5_USE_CACHE || $cache_fwrite) {
        $list = array();

        $sql = " select * from {$g5['board_table']} where bo_table = '{$bo_table}' ";
        $board = sql_fetch($sql);
        $bo_subject = get_text($board['bo_subject']);

        $tmp_write_table = $g5['write_prefix'] . $bo_table; // 게시판 테이블 전체이름
        $sql = " select * from {$tmp_write_table} where wr_is_comment = 0".$where." order by wr_num limit 0, {$rows} ";
       
        $result = sql_query($sql);
        for ($i=0; $row = sql_fetch_array($result); $i++) {
            $list[$i] = get_list($row, $board, $latest_skin_url, $subject_len);
        }

        if($cache_fwrite) {
            $handle = fopen($cache_file, 'w');
            $cache_content = "<?php\nif (!defined('_GNUBOARD_')) exit;\n\$bo_subject='".$bo_subject."';\n\$list=".var_export($list, true)."?>";
            fwrite($handle, $cache_content);
            fclose($handle);
        }
    }

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

    return $content;
}
?>
추천
1

댓글 9개


list($bo_table, $category) = explode("|", $bo_table);
if($category) {
	$cat = explode(",", $category);
	$where = " AND ca_name IN('".implode("', '", $cat)."') ";
}

<?=latest("theme/basic", "qa|답변,질문", 5, 25)?>
이런 식으로 넘기시면 기존에 코드를 이렇게만 바꾸시면 될 것 같네요.
테스트는 안 했습니다.
Warning: fopen(C:/APM_Setup/htdocs/g5/data/cache/latest-1-공지-basic-5-25.php) [function.fopen]: failed to open stream: Invalid argument in C:\APM_Setup\htdocs\g5\lib\latest.lib.php on line 85

Warning: fwrite(): supplied argument is not a valid stream resource in C:\APM_Setup\htdocs\g5\lib\latest.lib.php on line 87

Warning: fclose(): supplied argument is not a valid stream resource in C:\APM_Setup\htdocs\g5\lib\latest.lib.php on line 88

Warning: include(G5_THEME_PATH/skin/latest/basic/latest.skin.php) [function.include]: failed to open stream: No such file or directory in C:\APM_Setup\htdocs\g5\lib\latest.lib.php on line 93

Warning: include() [function.include]: Failed opening 'G5_THEME_PATH/skin/latest/basic/latest.skin.php' for inclusion (include_path='.') in C:\APM_Setup\htdocs\g5\lib\latest.lib.php on line 93
카테고리별로 최신글을 불러왔을때 타이틀 부분에 게시판명이 뜨는데요.. 혹시 불러온 카테고리명을 타이틀로 넣을 수 있을까요..?
전체 2,411 |RSS
그누보드5 팁자료실 내용 검색

회원로그인

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