원하는 최신글 게시물 보여주기

https://www.cosmosfarm.com/threads/document/26175

원하는 결과는 위의 링크의 내용과 많이 흡사합니다만 옵션필드 타입이 date 이고 

그 날짜(작성일이 아닙니다 새로 추가한 필드)를 오늘기준으로 가장 최신 게시물이 나오는 결과를 해보려고하는데 잘 되지않습니다.. 

예를 들면 

2007-01-24

2007-01-25

2007-01-26

2007-01-30

이렇게 데이타가 있을경우 3건만 뽑은다면 오늘날짜는 2007-01-25

2007-01-25

2007-01-26

2007-01-30

이런 결과를 얻고싶습니다.. 

 

해당 워드프레스 테마의 functoins.php 파일에서 

add_filter('kboard_list_select', 'my_kboard_list_select', 10, 3);
function my_kboard_list_select($select, $board_id, $content_list) {
 if($content_list->is_latest && $board_id == '해당게시판 id값'){ 
    $select .= ", `{$wpdb->prefix}kboard_board_option`.`option_value` as `custom_date`";
}

return $select;

}

add_filter('kboard_list_from', 'my_kboard_list_from', 10, 3);
function my_kboard_list_from($from, $board_id, $content_list){
 if($content_list->is_latest && $board_id == '해당게시판 id값'){ 
    $from .= " left join `{$wpdb->prefix}kboard_board_option` on {$from}.`uid` = `{$wpdb->prefix}kboard_board_option`.`content_uid` and `option_key` = 'custom_date'";
}
return $from;

}

 

add_filter('kboard_list_orderby', 'my_kboard_list_orderby', 10, 3);
function my_kboard_list_orderby($orderby, $board_id, $content_list) { 
 if($content_list->is_latest && $board_id == '해당게시판 id값'){ 
   $orderby = "`custom_date` DESC";
}
return $orderby;
 
}
add_filter('kboard_list_where', 'my_kboard_list_where', 10, 3);
function my_kboard_list_where($where, $board_id, $content_list){
    global $wpdb;
    if($content_list->is_latest && $board_id == '해당게시판 id값'){        
$where .= "code";

    }
return $where;
}

 

위의 함수 조건문에 어떤 코드를 작성해주어야할지 잘 모르겠습니다..

좋은 정보와 인맥을 동시에, 워드프레스 사용자 단톡방 참여하기
좋은 정보와 인맥을 동시에, 워드프레스 사용자 단톡방 참여하기
  • 안녕하세요~^^

    새로운 질문이 아니라 이어지는 질문이라면 이전 질문 페이지의 댓글로 남겨주세요.

    규칙이 지켜지지 않는다면 저희가 답변을 제대로 못 드릴 수 있습니다.

     

    올려주신 코드 대신 아래의 코드를 활용해보시겠어요?

    add_filter('kboard_list_from', 'my_kboard_list_from', 10, 3);
    function my_kboard_list_from($from, $board_id, $content_list){
    	global $wpdb;
    	if($content_list->is_latest && $board_id == '1'){
    		$from .= " LEFT JOIN `{$wpdb->prefix}kboard_board_option` ON `{$wpdb->prefix}kboard_board_content`.`uid`=`{$wpdb->prefix}kboard_board_option`.`content_uid`";
    	}
    	return $from;
    }
    
    add_filter('kboard_list_where', 'my_kboard_list_where', 10, 3);
    function my_kboard_list_where($where, $board_id, $content_list){
    	global $wpdb;
    	$option_key = 'custom_date';
    	if($content_list->is_latest && $board_id == '1'){
    		$where .= " AND (`option_key`='{$option_key}')";
    	}
    	return $where;
    }
    
    add_filter('kboard_list_orderby', 'my_kboard_list_orderby', 10, 3);
    function my_kboard_list_orderby($orderby, $board_id, $content_list){
    	global $wpdb;
    	if($content_list->is_latest && $board_id == '1'){
    		$orderby = "`{$wpdb->prefix}kboard_board_option`.`option_value` DESC";
    	}
    	return $orderby;
    }

    위의 코드에서 $board_id == '1' 부분은 실제 게시판 id로 적용해보세요.

    $option_key = 'custom_date' 부분은 실제 입력 필드 메타키로 적용해보세요.

    고맙습니다.

  • 답변 감사합니다. 

    답변 주신 내용중에서 오늘을 기준으로 날짜 비교하는 부분이 어디에 있는건가요???

  • 오늘을 기준으로 날짜를 비교하시려면

    아래의 코드를

    add_filter('kboard_list_where', 'my_kboard_list_where', 10, 3);
    function my_kboard_list_where($where, $board_id, $content_list){
    	global $wpdb;
    	$option_key = 'custom_date';
    	if($content_list->is_latest && $board_id == '1'){
    		$where .= " AND (`option_key`='{$option_key}')";
    	}
    	return $where;
    }

    아래의 코드로 교체해보시겠어요?

    add_filter('kboard_list_where', 'my_kboard_list_where', 10, 3);
    function my_kboard_list_where($where, $board_id, $content_list){
    	global $wpdb;
    	$option_key = 'custom_date';
    	$today = date('Y-m-d', current_time('timestamp'));
    	
    	if($content_list->is_latest && $board_id == '1'){
    		$where .= " AND (`option_key`='{$option_key}' AND `option_value`>='{$today}')";
    	}
    	return $where;
    }

    위의 코드를 적용하시면 오늘 날짜 이후의 게시글을 표시합니다.

    `option_value`>='{$today}' 부분을 `option_value`<='{$today}' 로 교체하시면

    오늘 날짜 이전의 게시글을 표시합니다.

     

    추가로 설명을 드리자면,

    이전 댓글에 안내해드린 아래의 코드를

    $orderby = "`{$wpdb->prefix}kboard_board_option`.`option_value` DESC";

    아래의 코드로 교체하시면 정렬 순서를 변경하실 수 있습니다.

    $orderby = "`{$wpdb->prefix}kboard_board_option`.`option_value` ASC";

    고맙습니다.

  • 답변감사합니다.

    답변 주신 위의 코드들을 적용해 보았는데 아래의 코드가 작동하지 않는 것 같습니다, 혹시 다른 수정할 곳이 더 있는건가요 ???

    add_filter('kboard_list_where', 'my_kboard_list_where', 10, 3);
    function my_kboard_list_where($where, $board_id, $content_list){
        global $wpdb;
        $option_key = 'custom_date';
        $today = date('Y-m-d', current_time('timestamp'));
    
        if($content_list->is_latest && (int)$board_id === 12){
            $where .= " AND (`option_key`='{$option_key}' AND `option_value`>='{$today}')";
        }
        return $where;
    }
    

     

    위의 $where을

    echo $where; 로 확인해보니

    `board_id`='12' AND `parent_uid`='0' AND (`status`='' OR `status` IS NULL OR `status`='pending_approval')
    위의 내용이 출력됩니다. 

    다른 방법으로도 확인을 해보니

    if($content_list->is_latest && $board_id == '12') {
    }

    위의 조건문에 내에 있는 내용은 아무것도 실행을 하지 않는걸로 보입니다.

  • 아래의 코드를

    $content_list->is_latest && $board_id == '12'

    아래의 코드로 교체해서 확인해보시겠어요?

    $content_list->is_latest

     

    실제 게시판의 id는 12번이 맞는지요?

    현재 사용 중이신 KBoard 플러그인의 버전은 어떻게 되시는지요?

    오래된 버전이라면 최신 버전으로 업데이트하신 후에 다시 확인해보시겠어요?

    업데이트 방법은 아래의 링크를 참고해보세요.

    KBoard(케이보드) 플러그인 업데이트 방법


    확인 가능한 페이지 주소도 알려주시겠어요?

    고맙습니다.

  • 답변감사합니다.

    하지만 실제 적용된 게시판의 id값은 12가 맞습니다... 

    • 설치된 게시판 플러그인 버전: 5.3.2 (최신: 5.3)
    • 설치된 댓글 플러그인 버전: 4.4.1 (최신: 4.4)

    적용된 페이지: http://math.postech.ac.kr/

  • KBoard 플러그인의 버전 문제인 듯합니다.

    최신 버전으로 업데이트하시면 해결되실 듯합니다.

    고맙습니다.

  • 답변 감사합니다. 

    KBoardBuilder.class.php 파일:
    
    
    public function createLatest(){
       ob_start();
    
       $list = new KBContentList($this->board_id);
           $list->is_latest = true;
       $list->category1($this->category1);
       $list->category2($this->category2);
       $list->setSorting($this->sort);
       $list->rpp($this->rpp)->getList('', '', true);
    
       $vars = array(
             'board_url' => $this->url,
             'list' => $list,
             'url' => new KBUrl(),
             'skin_path' => $this->skin->url($this->skin_name),
             'skin_dir' => $this->skin->dir($this->skin_name),
             'board' => $this->board,
             'boardBuilder' => $this,
       );
    
       echo $this->skin->load($this->skin_name, 'latest.php', $vars);
    
       return ob_get_clean();
    }

     

     

    위의 부분에서  
    $list->is_latest = true; 
    가 누락되어서 echo가 나오지 않았덜걸로 확인됩니다.

    실마리를 많이 찾아가고 있는데 답변주신 내용 정말 많은 도움 된것같습니다. 감사합니다.

좋은 정보와 인맥을 동시에, 워드프레스 사용자 단톡방 참여하기