채택완료

[그누커머스] 최신글을 가져올 때 카테고리를 선택하고 싶습니다.

2016-10-24 (월) 10:58:15 11,309

워드프레스에서 그누커머스 게시판을 사용중에 있습니다.

[gnucommerce_board_latest bo_table=Nnotice url=페이지주소 rows=3 skin_dir=index_notice] 

위의 코드로 현재 최신글을 불러오고 있습니다.

이렇게 불러올 경우 Nnotice 라는 게시판에 있는 모든 글이 불러들여 지는데요~

제가 내부 / 외부 의 카테고리를 만들었을 때,

내부 혹은 외부 카테고리에 선택되어진 게시글말 최신글로 불러올 방법이 없을까요?

워드프레스가 너무 어렵네요 ㅠ_ㅠ

그럼 좋은 하루 보내세요~

답변 1개

채택된 답변
+20 포인트

gnucommerce/lib/gc_board.class.php

파일에 보시면 448번째 줄에

    //최신글 숏코드 실행

    public function gc_latest_shortcode($attr=array()){

라고 되어 있는 부분이 있습니다.

해당 부분의 메소드를 아래와 같이 바꿔주세요. 바뀐 부분은 다음 업데이트시 반영될 것입니다.

Copy
//최신글 숏코드 실행    public function gc_latest_shortcode($attr=array()){        global $wpdb;         $gc = $this->gc;         if( ! isset($attr['bo_table']) && empty($attr['bo_table']) ){            $gc_error = new WP_Error( 'broke', __( "shortcode에 반드시 bo_table 값을 입력해 주세요.", GC_NAME ) );   //shortcode에 반드시 bo_table값을 입력해 주세요.            return $gc_error->get_error_message();        }                $arg = wp_parse_args($attr, array(                'is_latest' => true,                'skin_dir' => 'basic',                'bo_table' => '',                'rows' => 5,                'subject_len' => 40,                'cache_time' => 1,                'options' => '',                'category'  =>  '',        ));         extract( $arg );         $latest_skin_path = gc_latest_get_skin_path('latest.skin.php', array('skin_dir_path'=>$skin_dir));         $latest_skin_url  = str_replace(substr(ABSPATH, 0, -1), site_url(), $latest_skin_path);        $latest_skin_url = str_replace('\\', '/', $latest_skin_url);        $latest_skin_url = str_replace('/latest.skin.php', '', $latest_skin_url);         $use_latest_cache = $this->board_config['cf_use_latest_cache'];         $cache_file_path = gc_get_upload_path();         $cache_fwrite = false;         if( $use_latest_cache && $cache_file_path ){            $cache_file = apply_filters('gc_latest_cache_filename', $cache_file_path."/cache/latest-{$bo_table}-{$skin_dir}-{$rows}-{$subject_len}-".urlencode($category).".php", $cache_file_path, $bo_table, $skin_dir, $rows, $subject_len);             if(!file_exists($cache_file)) {                $cache_fwrite = true;            } else {                if($cache_time > 0) {                    $system_time = time();                    $filetime = filemtime($cache_file);                     if($filetime && $filetime < ($system_time - 3600 * $cache_time)) {                        @unlink($cache_file);                        $cache_fwrite = true;                    }                }                 if(!$cache_fwrite){                    $list = maybe_unserialize(@file_get_contents($cache_file));                }            }        }         if( !$use_latest_cache || $cache_fwrite){            $list = array();             if( $this->latest === null ){                GC_Board_var::getInstance()->need_value_load();                include_once( GC_LIB_PATH.'/gc_board_common.class.php' );                include_once( GC_LIB_PATH.'/gc_board_load.class.php' );                include_once( GC_LIB_PATH.'/gc_board_taxonomy.lib.php' );                 $this->latest = new GC_Board_load($attr);            }             $board = gc_get_board_config($bo_table);             if( !isset($board['bo_table']) || empty($board['bo_table']) ){                $gc_error = new WP_Error( 'broke', __( "데이터가 없습니다.", GC_NAME) );   //데이터가 없습니다.                return $gc_error->get_error_message();            }             $bo_table = $board['bo_table'];            $bo_subject = gc_get_text($board['bo_subject']);             $add_where = '';             if( $category ){                $add_where = $wpdb->prepare(" and ca_name = '%s' ", $category);            }             $sql = $wpdb->prepare("select * from {$gc['write_table']} where bo_table = '%s' and wr_parent = 0 $add_where order by wr_num limit 0, %d ", $bo_table, $rows);            $sql = apply_filters('gc_get_latest_sql', $sql, $gc['write_table'], $bo_table, $rows);             $lists = $wpdb->get_results($sql, ARRAY_A);                        $i = 0;            foreach($lists as $row){                 if( empty($row) ) continue;                 $list[$i] = $this->latest->get_list($row, $board, $latest_skin_url, $subject_len);                if( $board['page_url'] ){                    $list[$i]['href'] = add_query_arg( array('wr_id'=>$row['wr_id']) , $board['page_url']);                } else {                    if( $row['wr_page_id'] ){                        $list[$i]['href'] = add_query_arg( array('wr_id'=>$row['wr_id']) , get_permalink($row['wr_page_id']) );                    } else {                        $list[$i]['href'] = "#no_value_link";                    }                }                $list[$i]['bo_subject'] = $bo_subject;                $i++;                $list[$i]['user_pass'] = '';    //유저 패스워드는 저장하지 않음            }             if($cache_fwrite) {                $handle = fopen($cache_file, 'w');                $cache_content = maybe_serialize($list, true);                if (flock($handle, LOCK_EX)) { // do an exclusive lock                    fwrite($handle, $cache_content);                    flock($handle, LOCK_UN); // release the lock                }                fclose($handle);            }        }                //최신글 스킨별 css 중복 로드 방지        if( !isset($this->latest_skin[$bo_table.'_css']) ){             if( is_file( str_replace('/latest.skin.php', '', $latest_skin_path).'/style.css' ) ){                wp_enqueue_style ( GC_NAME.'_board_latest_'.$bo_table , $latest_skin_url.'/style.css', '', GC_VERSION );            }            $this->latest_skin[$bo_table.'_css'] = true;        }         $bo_subject = isset($bo_subject) ? $bo_subject : '';        if( !$bo_subject ){            $bo_subject = isset($list[0]['bo_subject']) ? $list[0]['bo_subject'] : '';        }         $gc_page_url = gc_page_get_by($bo_table, 'url' );        ob_start();        if ( !file_exists($latest_skin_path) ) {  //해당 파일이 없으면            echo sprintf( '<code>%s</code> '.__('파일이 존재하지 않습니다.', GC_NAME), $latest_skin_path );        } else {            include $latest_skin_path;        }        $content = ob_get_contents();        ob_end_clean();         return $content;    }

그리고 나서 숏코드를 아래와 같이 적용합니다.

[gnucommerce_board_latest bo_table=Nnotice url=페이지주소 rows=3 skin_dir=index_notice category='해당카테고리']  

답변을 작성하려면 로그인이 필요합니다.