[그누커머스] 최신글을 가져올 때 카테고리를 선택하고 싶습니다. 채택완료
명준
9년 전
조회 10,550
워드프레스에서 그누커머스 게시판을 사용중에 있습니다.
[gnucommerce_board_latest bo_table=Nnotice url=페이지주소 rows=3 skin_dir=index_notice]
위의 코드로 현재 최신글을 불러오고 있습니다.
이렇게 불러올 경우 Nnotice 라는 게시판에 있는 모든 글이 불러들여 지는데요~
제가 내부 / 외부 의 카테고리를 만들었을 때,
내부 혹은 외부 카테고리에 선택되어진 게시글말 최신글로 불러올 방법이 없을까요?
워드프레스가 너무 어렵네요 ㅠ_ㅠ
그럼 좋은 하루 보내세요~
댓글을 작성하려면 로그인이 필요합니다.
답변 1개
채택된 답변
+20 포인트
9년 전
gnucommerce/lib/gc_board.class.php
파일에 보시면 448번째 줄에
//최신글 숏코드 실행
public function gc_latest_shortcode($attr=array()){
라고 되어 있는 부분이 있습니다.
해당 부분의 메소드를 아래와 같이 바꿔주세요. 바뀐 부분은 다음 업데이트시 반영될 것입니다.
</p><p> //최신글 숏코드 실행</p><p> public function gc_latest_shortcode($attr=array()){</p><p> global $wpdb;</p><p> </p><p> $gc = $this->gc;</p><p> </p><p> if( ! isset($attr['bo_table']) && empty($attr['bo_table']) ){</p><p> $gc_error = new WP_Error( 'broke', __( "shortcode에 반드시 bo_table 값을 입력해 주세요.", GC_NAME ) ); //shortcode에 반드시 bo_table값을 입력해 주세요.</p><p> return $gc_error->get_error_message();</p><p> }</p><p> </p><p> $arg = wp_parse_args($attr, array(</p><p> 'is_latest' => true,</p><p> 'skin_dir' => 'basic',</p><p> 'bo_table' => '',</p><p> 'rows' => 5,</p><p> 'subject_len' => 40,</p><p> 'cache_time' => 1,</p><p> 'options' => '',</p><p> 'category' => '',</p><p> ));</p><p> </p><p> extract( $arg );</p><p> </p><p> $latest_skin_path = gc_latest_get_skin_path('latest.skin.php', array('skin_dir_path'=>$skin_dir));</p><p> </p><p> $latest_skin_url = str_replace(substr(ABSPATH, 0, -1), site_url(), $latest_skin_path);</p><p> $latest_skin_url = str_replace('\\', '/', $latest_skin_url);</p><p> $latest_skin_url = str_replace('/latest.skin.php', '', $latest_skin_url);</p><p> </p><p> $use_latest_cache = $this->board_config['cf_use_latest_cache'];</p><p> </p><p> $cache_file_path = gc_get_upload_path();</p><p> </p><p> $cache_fwrite = false;</p><p> </p><p> if( $use_latest_cache && $cache_file_path ){</p><p> $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);</p><p> </p><p> if(!file_exists($cache_file)) {</p><p> $cache_fwrite = true;</p><p> } else {</p><p> if($cache_time > 0) {</p><p> $system_time = time();</p><p> $filetime = filemtime($cache_file);</p><p> </p><p> if($filetime && $filetime < ($system_time - 3600 * $cache_time)) {</p><p> @unlink($cache_file);</p><p> $cache_fwrite = true;</p><p> }</p><p> }</p><p> </p><p> if(!$cache_fwrite){</p><p> $list = maybe_unserialize(@file_get_contents($cache_file));</p><p> }</p><p> }</p><p> }</p><p> </p><p> if( !$use_latest_cache || $cache_fwrite){</p><p> $list = array();</p><p> </p><p> if( $this->latest === null ){</p><p> GC_Board_var::getInstance()->need_value_load();</p><p> include_once( GC_LIB_PATH.'/gc_board_common.class.php' );</p><p> include_once( GC_LIB_PATH.'/gc_board_load.class.php' );</p><p> include_once( GC_LIB_PATH.'/gc_board_taxonomy.lib.php' );</p><p> </p><p> $this->latest = new GC_Board_load($attr);</p><p> }</p><p> </p><p> $board = gc_get_board_config($bo_table);</p><p> </p><p> if( !isset($board['bo_table']) || empty($board['bo_table']) ){</p><p> $gc_error = new WP_Error( 'broke', __( "데이터가 없습니다.", GC_NAME) ); //데이터가 없습니다.</p><p> return $gc_error->get_error_message();</p><p> }</p><p> </p><p> $bo_table = $board['bo_table'];</p><p> $bo_subject = gc_get_text($board['bo_subject']);</p><p> </p><p> $add_where = '';</p><p> </p><p> if( $category ){</p><p> $add_where = $wpdb->prepare(" and ca_name = '%s' ", $category);</p><p> }</p><p> </p><p> $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);</p><p> $sql = apply_filters('gc_get_latest_sql', $sql, $gc['write_table'], $bo_table, $rows);</p><p> </p><p> $lists = $wpdb->get_results($sql, ARRAY_A);</p><p> </p><p> $i = 0;</p><p> foreach($lists as $row){</p><p> </p><p> if( empty($row) ) continue;</p><p> </p><p> $list[$i] = $this->latest->get_list($row, $board, $latest_skin_url, $subject_len);</p><p> if( $board['page_url'] ){</p><p> $list[$i]['href'] = add_query_arg( array('wr_id'=>$row['wr_id']) , $board['page_url']);</p><p> } else {</p><p> if( $row['wr_page_id'] ){</p><p> $list[$i]['href'] = add_query_arg( array('wr_id'=>$row['wr_id']) , get_permalink($row['wr_page_id']) );</p><p> } else {</p><p> $list[$i]['href'] = "#no_value_link";</p><p> }</p><p> }</p><p> $list[$i]['bo_subject'] = $bo_subject;</p><p> $i++;</p><p> $list[$i]['user_pass'] = ''; //유저 패스워드는 저장하지 않음</p><p> }</p><p> </p><p> if($cache_fwrite) {</p><p> $handle = fopen($cache_file, 'w');</p><p> $cache_content = maybe_serialize($list, true);</p><p> if (flock($handle, LOCK_EX)) { // do an exclusive lock</p><p> fwrite($handle, $cache_content);</p><p> flock($handle, LOCK_UN); // release the lock</p><p> }</p><p> fclose($handle);</p><p> }</p><p> }</p><p> </p><p> //최신글 스킨별 css 중복 로드 방지</p><p> if( !isset($this->latest_skin[$bo_table.'_css']) ){</p><p> </p><p> if( is_file( str_replace('/latest.skin.php', '', $latest_skin_path).'/style.css' ) ){</p><p> wp_enqueue_style ( GC_NAME.'_board_latest_'.$bo_table , $latest_skin_url.'/style.css', '', GC_VERSION );</p><p> }</p><p> $this->latest_skin[$bo_table.'_css'] = true;</p><p> }</p><p> </p><p> $bo_subject = isset($bo_subject) ? $bo_subject : '';</p><p> if( !$bo_subject ){</p><p> $bo_subject = isset($list[0]['bo_subject']) ? $list[0]['bo_subject'] : '';</p><p> }</p><p> </p><p> $gc_page_url = gc_page_get_by($bo_table, 'url' );</p><p> ob_start();</p><p> if ( !file_exists($latest_skin_path) ) { //해당 파일이 없으면</p><p> echo sprintf( '<code>%s</code> '.__('파일이 존재하지 않습니다.', GC_NAME), $latest_skin_path );</p><p> } else {</p><p> include $latest_skin_path;</p><p> }</p><p> $content = ob_get_contents();</p><p> ob_end_clean();</p><p> </p><p> return $content;</p><p> }</p><p>
그리고 나서 숏코드를 아래와 같이 적용합니다.
[gnucommerce_board_latest bo_table=Nnotice url=페이지주소 rows=3 skin_dir=index_notice category='해당카테고리']
로그인 후 평가할 수 있습니다
댓글을 작성하려면 로그인이 필요합니다.
답변을 작성하려면 로그인이 필요합니다.
로그인