[전체게시판] 일일/주간/월간 인기 게시물 > 그누보드5 팁자료실

그누보드5 팁자료실

[전체게시판] 일일/주간/월간 인기 게시물 정보

[전체게시판] 일일/주간/월간 인기 게시물

첨부파일

index.php (7.1K) 8회 다운로드 2025-05-02 21:41:27

본문

[전체게시판] 일일/주간/월간 인기 게시물 (원본: 미니님a)

 

// 출력할 게시물 수
$rows = 10;

// 각 기간별 게시물을 가져오는 함수
function get_popular_posts($period, $rows) {
    global $g5;
    
    $today = date('Y-m-d');
    
    switch($period) {
        case 'daily':
            $start_date = date('Y-m-d', strtotime('-3 day'));
            break;
        case 'weekly':
            $start_date = date('Y-m-d', strtotime('-7 days'));
            break;
        case 'monthly':
            $start_date = date('Y-m-d', strtotime('-30 days'));
            break;
        default:
            $start_date = date('Y-m-d', strtotime('-3 day'));
    }
    
    $list = array();
    
    // 모든 게시판 가져오기
    $board_sql = "SELECT bo_table FROM {$g5['board_table']} WHERE bo_use_search = 1";
    $board_result = sql_query($board_sql);
    
    // 모든 게시판의 인기글을 통합하여 가져옴
    $sql = " SELECT 
                a.bo_table,
                a.wr_id,
                a.wr_subject,
                a.wr_comment,
                a.wr_hit,
                a.wr_datetime
            FROM (";
    
    $union_sql = array();
    
    while ($board = sql_fetch_array($board_result)) {
        $bo_table = $board['bo_table'];
        
        // 게시판 테이블이 존재하는지 확인
        $table_exists = sql_query("SHOW TABLES LIKE '{$g5['write_prefix']}{$bo_table}'", false);
        if (sql_num_rows($table_exists) == 0) continue;
        
        $union_sql[] = " SELECT 
                '{$bo_table}' as bo_table,
                wr_id,
                wr_subject,
                wr_comment,
                wr_hit,
                wr_datetime
            FROM {$g5['write_prefix']}{$bo_table}
            WHERE wr_is_comment = 0
                AND wr_datetime BETWEEN '{$start_date} 00:00:00' AND '{$today} 23:59:59'";
    }
    
    // UNION ALL 쿼리 생성
    if (count($union_sql) > 0) {
        $sql .= implode(" UNION ALL ", $union_sql);
        $sql .= ") a ORDER BY a.wr_hit DESC, a.wr_comment DESC LIMIT 0, {$rows} ";
        
        $result = sql_query($sql);
        
        for ($i=0; $row = sql_fetch_array($result); $i++) {
            $list[$i]['bo_table'] = $row['bo_table'];
            $list[$i]['wr_id'] = $row['wr_id'];
            $list[$i]['subject'] = $row['wr_subject'];
            $list[$i]['comment_cnt'] = $row['wr_comment'];
            $list[$i]['hit'] = $row['wr_hit'];
            $list[$i]['datetime'] = $row['wr_datetime'];
            
            // 게시판 제목 가져오기
            $board_info = sql_fetch("SELECT bo_subject FROM {$g5['board_table']} WHERE bo_table = '{$row['bo_table']}'");
            $list[$i]['bo_subject'] = $board_info['bo_subject'];
        }
    }
    
    return $list;
}

추천
2

댓글 6개

@무와보 

 

안녕하세요. 미나님의 스킨은 일정게시판을 추가하면서 인기게시물을 뽑는 함수인데 

 

저는 이를 변형해서 모든(개설된 전체)게시판에서 인기게시물로 뽑는 함수로 변경하였습니다.

 

자세한 설명이 없었네요...

 

전체 2,638 |RSS
그누보드5 팁자료실 내용 검색

회원로그인

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