http://www.cosmosfarm.com/threads/document/10754
검색하다 여기 글을 보고 문의드립니다.
코드를 보면 답변 주신대로 uid 값이 기준이 되는 거 같은데
이걸 date나 update로 변경하는 방법에 대해 조언 좀 부탁드립니다...!
먼저 아래 코드를 테마의 functions.php 파일에 추가해주세요.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 | function get_next_content_uid( $board_id , $current_uid , $key , $value ){ global $wpdb ; $board_id = intval ( $board_id ); $current_uid = intval ( $current_uid ); $key = esc_sql(sanitize_key( $key )); $value = esc_sql(sanitize_text_field( $value )); $where [] = "`board_id`='{$board_id}'" ; $where [] = "`uid`!='{$current_uid}'" ; $where [] = "`$key`>='{$value}'" ; // 휴지통에 없는 게시글만 불러온다. $where [] = "(`status`='' OR `status` IS NULL OR `status`='pending_approval')" ; $category1 = kboard_category1(); $category2 = kboard_category2(); if ( $category1 ){ $category1 = esc_sql( $category1 ); $where [] = "`category1`='{$category1}'" ; } if ( $category2 ){ $category2 = esc_sql( $category2 ); $where [] = "`category2`='{$category2}'" ; } $where = implode( ' AND ' , $where ); $uid = $wpdb ->get_var( "SELECT `uid` FROM `{$wpdb->prefix}kboard_board_content` WHERE {$where} ORDER BY `{$key}` ASC LIMIT 1" ); return intval ( $uid ); } function get_prev_content_uid( $board_id , $current_uid , $key , $value ){ global $wpdb ; $board_id = intval ( $board_id ); $current_uid = intval ( $current_uid ); $key = esc_sql(sanitize_key( $key )); $value = esc_sql(sanitize_text_field( $value )); $where [] = "`board_id`='{$board_id}'" ; $where [] = "`uid`!='{$current_uid}'" ; $where [] = "`$key`<='{$value}'" ; // 휴지통에 없는 게시글만 불러온다. $where [] = "(`status`='' OR `status` IS NULL OR `status`='pending_approval')" ; $category1 = kboard_category1(); $category2 = kboard_category2(); if ( $category1 ){ $category1 = esc_sql( $category1 ); $where [] = "`category1`='{$category1}'" ; } if ( $category2 ){ $category2 = esc_sql( $category2 ); $where [] = "`category2`='{$category2}'" ; } $where = implode( ' AND ' , $where ); $uid = $wpdb ->get_var( "SELECT `uid` FROM `{$wpdb->prefix}kboard_board_content` WHERE {$where} ORDER BY `{$key}` DESC LIMIT 1" ); return intval ( $uid ); } |
그 다음 게시판 스킨의 document.php 파일을 수정해주세요.
$bottom_content_uid = $content->getPrevUID();
위 코드를 찾아서 아래 코드로 바꿔주세요.
$bottom_content_uid = get_prev_content_uid($board->id, $content->uid, 'date', $content->date);
마찬가지로
$top_content_uid = $content->getNextUID();
위 코드를 찾아서 아래 코드로 바꿔주세요.
$top_content_uid = get_next_content_uid($board->id, $content->uid, 'date', $content->date);
아래처럼 사용하시면 update 기준으로 이전글 다음글의 uid값을 가져올 수 있습니다.
$bottom_content_uid = get_prev_content_uid($board->id, $content->uid, 'update', $content->update);
$top_content_uid = get_next_content_uid($board->id, $content->uid, 'update', $content->update);
감사합니다.
참고해서 적용토록 하겠습니다!
AI 상담