개선/제안

2026.07.24 06:56

최신글 출력 옵션에 기간 추가 / 이미지 글만

모듈에서 최신글 출력 옵션에 기간을 선택할 수 있으면, 최신글로 일간, 주간, 월간 또는 특정 기간 인기글을 통합하는 최신글이 될 수 있을꺼 같아요.

그누보드 원본 수정을 하지 않고 hook을 이용한다면 아래 코드로도 가능할꺼 같아요. (참고)


<?php
if (!defined('_GNUBOARD_')) exit; // 개별 페이지 접근 불가

// 1. 최신글 쿼리를 변경하는 필터 훅 등록
add_filter('latest_query', 'extend_latest_hit_query', 10, 4);

function extend_latest_hit_query($sql, $bo_table, $rows, $options)
{
global $g5;

// 옵션에 hit_period(기간) 값이 넘어온 경우에만 인기글 쿼리로 변경
if (isset($options['hit_period']) && is_numeric($options['hit_period'])) {

$period = (int)$options['hit_period'];

// 기간 설정 (현재 서버 시간 기준 $period 일 전)
$target_time = date("Y-m-d H:i:s", G5_SERVER_TIME - (86400 * $period));

$tmp_write_table = $g5['write_prefix'] . $bo_table;

// 지정 기간 내 조회수가 높은 순(wr_hit DESC)으로 쿼리 재구성
$sql = " select * from {$tmp_write_table}
where wr_is_comment = 0
and wr_datetime >= '{$target_time}'
order by wr_hit desc
limit 0, {$rows} ";
}

return $sql;
}

혹시 이미지가 포함된 글에서만 기간 옵션까지.. (참고)


<?php
if (!defined('_GNUBOARD_')) exit; // 개별 페이지 접근 불가

// 최신글 쿼리를 변경하는 필터 훅 등록
add_filter('latest_query', 'extend_latest_img_query', 10, 4);

function extend_latest_img_query($sql, $bo_table, $rows, $options)
{
global $g5;

// 옵션에 only_img 값이 true로 넘어온 경우 처리
if (isset($options['only_img']) && $options['only_img'] === true) {

$tmp_write_table = $g5['write_prefix'] . $bo_table;

// 기본 이미지 추출 조건 조건 (첨부파일이 있거나 본문에 img 태그가 포함된 경우)
$where_img = " and (wr_file > 0 or wr_content like '%<img%') ";

// 만약 기간별 인기글(hit_period) 조건도 함께 사용한다면
if (isset($options['hit_period']) && is_numeric($options['hit_period'])) {
$period = (int)$options['hit_period'];
$target_time = date("Y-m-d H:i:s", G5_SERVER_TIME - (86400 * $period));

// [인기글 + 이미지 필수] 쿼리
$sql = " select * from {$tmp_write_table}
where wr_is_comment = 0
{$where_img}
and wr_datetime >= '{$target_time}'
order by wr_hit desc
limit 0, {$rows} ";
} else {
// [단순 최신글 + 이미지 필수] 쿼리
$sql = " select * from {$tmp_write_table}
where wr_is_comment = 0
{$where_img}
order by wr_num, wr_reply
limit 0, {$rows} ";
}
}

return $sql;
}






  • 공유링크 복사
    미니홈 쪽지 구독하기
    구독하고 알림받기

    댓글목록

    profile_image
    리빌더미니홈 1:1 대화하기  6일 전

    좋은의견 감사합니다.
    2.2.7 버전에 적용하도록 하겠습니다.

    감사합니다.

    2026-07-24 15:23