게시글 분류 2개 이상 중복 체크 시 최신글 latest 가져오는 법..
본문
위 글 참고하여 현재 분류(ca_name)를 중복 체크하여 사용하고 있습니다.
분류가 하나일 때는 분류별로 최신글 가져오는 방법이 많지만, 분류가 2개 이상일 때는 어떻게 뿌려줘야 할 지가 궁금합니다.
latest로 A 라는 분류를 포함하는 게시글만 불러오고 싶다고 가정 시,
분류가 [A, B, C, D] 인 글은 불러와지고 A가 없이 [B, C, D] 인 글은 불러오지 못하도록요..
질문이 두서가 없는데
방법 아시는 분 계신가요?
답변 2
latest 의 경우
https://github.com/gnuboard/gnuboard5/blob/master/lib/latest.lib.php
에 있는 function latest 를 거치는것 같고
함수 인자 및 쿼리를 다음처럼 수정해 볼수 있습니다.
function latest($skin_dir='', $bo_table, $rows=10, $subject_len=40, $cache_time=1, $options='', $ca_name='')
{
...
$sql = " select * from {$tmp_write_table} where wr_is_comment = 0 order by wr_num limit 0, {$rows} ";
if (empty($ca_name) == false) {
$sql = str_replace('where wr_is_comment = 0', "where wr_is_comment = 0 and instr(ca_name, '${ca_name}') > 0", $sql);
}
...
}
<?php
$sql = "SELECT a.bo_table, a.bo_subject
FROM {$g5['board_table']} a
LEFT JOIN {$g5['group_table']} b ON (a.gr_id = b.gr_id)
LEFT JOIN {$g5['category_table']} c ON (a.bo_table = c.bo_table)
WHERE a.bo_device <> 'mobile'
AND a.bo_use_cert = ''
AND a.bo_table NOT IN ('free','gallery','qa')
AND (
a.bo_table IN (SELECT bo_table FROM {$g5['category_table']} WHERE ca_name = 'A')
OR c.ca_name = 'A'
)
ORDER BY b.gr_order, a.bo_order";
$result = sql_query($sql);
?>
서버쪽을 이렇게 정의 하시고 시작하면될것 같네요