[임시] 최근글 리스트 뽑아오기 숏코드

안녕하세요, 오늘 KBOARD를 처음 설치해보고 최근글 리스트 가져오는 숏코드가 없어 간단하게(당장 그냥 쓸수만 있도록?) 만들었습니다

검색해보니 KBOARD 개발자분이 향후 추가 할 예정이라고 하니 급하신 분들만 쓰시라고 공유해드립니다

 

1. 소스코드 추가

/wp-content/plugins/kboard/index.php 를 열어서

add_shortcode("kboard", "kboard_builder");
function kboard_builder($atts){
...

이 부분 위쪽에 아래 코드를 추가합니다

/**
 * 메인페이지 최근글 리스트 숏코드
 * @Author : www.plannity.kr
 */
add_shortcode("kboard_recent", "kboard_recent");
function kboard_recent($attr){
    global $wpdb;
     
    if(!$attr['id']){
        return 'KBoard 알림 :: id=null, 아이디값은 필수 입니다.'
    }
    else{
        $id = $attr['id'];
    }
     
    $count = 5; // Default 갯수
    if($attr['count'] || $attr['count']>0) {
        $count = $attr['count'];
    }
     
    $attr['count'] || $attr['count']>0 ? $count = $attr['count'] : ''
    $sql = "SELECT * FROM kboard_board_content WHERE board_id = '$id' order by date desc limit $count";
    $result = $wpdb->get_results($sql);
    if($result){
        $html = "";
        foreach($result as $key => $val){
            $titleClass = "";
            if(date('Y-m-d')==date('Y-m-d', strtotime($val->date))){
                $titleClass.="new ";
            }
            $html .= "".$val->title."";
            $html .= "".date('Y-m-d', strtotime($val->date))."";
        }
        $html .= "";
    }
     
    return $html;
}

 

2. 숏코드 사용하기

[kboard_recent id=게시판아이디 count=가져올글수]

예) [kboard_recent id=112 count=5]

1) count를 지정하지 않으시면 기본 5개를 불러옵니다

2) 오늘 작성된 글의 경우 new 클래스를 사용합니다

3) 해당 리스트를 멋들어지게 만들기 위해서는 css를 수정하셔야 합니다

 

3. 숏코드 결과


 

test

2013-06-03

 

* 버전업시 코드는 삭제됩니다. 하지만 다음버전에는 개발자분께서 만들어주신 숏코드가 들어있으리라 생각됩니다 :)

* to 개발자님 : 혹시라도 제 글이 문제가 된다면 수정/삭제 하셔도 무방합니다

 

좋은 정보와 인맥을 동시에, 워드프레스 사용자 단톡방 참여하기
워드프레스 에러 기술지원 서비스 전문가에게 맡기세요
  • 이대로 따라서 코드를 넣는데 왜 오류가 날까요 ㅠㅠ 서버가 다운되네요... 뭐가 문젤까요...

    ㅠㅠ

  • /**
     * 메인페이지 최근글 리스트 숏코드
     * @Author : www.plannity.kr
     */
    add_shortcode("kboard_recent", "kboard_recent");
    function kboard_recent($attr){
    	global $wpdb;
    	
    	if(!$attr['id']){
    		return 'KBoard 알림 :: id=null, 아이디값은 필수 입니다.'
    	}
    	else{
    		$id = $attr['id'];
    	}
    	
    	$count = 5; // Default 갯수
    	if($attr['count'] || $attr['count']>0) {
    		$count = $attr['count'];
    	}
    	
    	$attr['count'] || $attr['count']>0 ? $count = $attr['count'] : ''
    	$sql = "SELECT * FROM kboard_board_content WHERE board_id = '$id' order by date desc limit $count";
    	$result = $wpdb->get_results($sql);
    	if($result){
    		$html = "";
    		foreach($result as $key => $val){
    			$titleClass = "";
    			if(date('Y-m-d')==date('Y-m-d', strtotime($val->date))){
    				$titleClass.="new ";
    			}
    			$html .= "".$val->title."";
    			$html .= "".date('Y-m-d', strtotime($val->date))."";
    		}
    		$html .= "";
    	}
    	
    	return $html;
    }
  • 터프키드님 소스 제공해주셔서 감사합니다.

    테스트 해본 결과 잘 출력 됩니다.

  • 봉소님, 터프키드님이 코드에 사소한 에러가 있었네요. Parsing 할 때 ; 가 없었던 것이 두세군데? 있었던 것 같아요.

    아래 수정한 코드 쓰시면 될거에요. :)

    코드 만들어주신 터프키드님께도 감사를...

    /**
     * 메인페이지 최근글 리스트 숏코드
     * @Author : www.plannity.kr
     */
    add_shortcode("kboard_recent", "kboard_recent");
    function kboard_recent($attr){
        global $wpdb;
         
        if(!$attr['id']){
            return 'KBoard 알림 :: id=null, 아이디값은 필수 입니다.'
        }
        else{
            $id = $attr['id'];
        }
         
        $count = 5; // Default 갯수
        if($attr['count'] || $attr['count']>0) {
            $count = $attr['count'];
        }
         
        $attr['count'] || $attr['count']>0 ? $count = $attr['count'] : ''
        $sql = "SELECT * FROM kboard_board_content WHERE board_id = '$id' order by date desc limit $count;";
        $result = $wpdb->get_results($sql);
        if($result){
            $html = "";
            foreach($result as $key => $val){
                $titleClass = "";
                if(date('Y-m-d')==date('Y-m-d', strtotime($val->date))){
                    $titleClass.="new ";
                }
                $html .= "".$val->title."";
                $html .= "".date('Y-m-d', strtotime($val->date))."";
            }
            $html .= "";
        }
         
        return $html;
    }

     

  • 흠.. 터프키드님이 주신 코드에 문제가 있었던 것이 아니라 코드입력기가 자동으로 '' 몇개를 먹어버리는 군요.

    코드 입력기 안쓰고 다시 올려봅니다..

    /**
     * 메인페이지 최근글 리스트 숏코드
     * @Author : www.plannity.kr
     */
    add_shortcode("kboard_recent", "kboard_recent");
    function kboard_recent($attr){
        global $wpdb;
         
        if(!$attr['id']){
            return 'KBoard 알림 :: id=null, 아이디값은 필수 입니다.'
        }
        else{
            $id = $attr['id'];
        }
         
        $count = 5; // Default 갯수
        if($attr['count'] || $attr['count']>0) {
            $count = $attr['count'];
        }
         
        $attr['count'] || $attr['count']>0 ? $count = $attr['count'] : ''
        $sql = "SELECT * FROM kboard_board_content WHERE board_id = '$id' order by date desc limit $count;";
        $result = $wpdb->get_results($sql);
        if($result){
            $html = "";
            foreach($result as $key => $val){
                $titleClass = "";
                if(date('Y-m-d')==date('Y-m-d', strtotime($val->date))){
                    $titleClass.="new ";
                }
                $html .= "".$val->title."";
                $html .= "".date('Y-m-d', strtotime($val->date))."";
            }
            $html .= "";
        }
         
        return $html;
    }

  • KBoard 1.8 버전에 최신글 리스트 생성기능이 추가 되었습니다.^^

    KBoard 발전에 힘써주시는 모든 분들게 감사의 인사 드립니다!!

워드프레스 에러 기술지원 서비스 전문가에게 맡기세요