최신글 추출에서 여분필드5 분류 부분 추출 하려면
본문
<?php echo latest("test", "0201 | 분류3 ",3,50, 25)?>
이렇게 해서 게시판의 분류 , 분류3을 메인화면에 추출 했는데요.
2차 분류를 또 만들어 넣어서
여분 필드5( wr_5 필드)에 서브분류1 | 서브분류2 | 서브분류3 이렇게 넣었습니다.
그리고
<?php echo latest("test", "0201 | 서브분류3 ",3,50, 25)?>
이렇게 했더니 안되네요..
서브분류3의 내용을 추출 방법이 없을까요?
<?php if (!defined('_GNUBOARD_')) exit; // 최신글 추출 // $cache_time 캐시 갱신시간 function latest_cate($skin_dir='', $bo_table, $rows=10, $subject_len=40, $cache_time=1, $options='',$category="") { global $g5; if (!$skin_dir) $skin_dir = 'basic'; if(preg_match('#^theme/(.+)$#', $skin_dir, $match)) { if (G5_IS_MOBILE) { $latest_skin_path = G5_THEME_MOBILE_PATH.'/'.G5_SKIN_DIR.'/latest/'.$match[1]; if(!is_dir($latest_skin_path)) $latest_skin_path = G5_THEME_PATH.'/'.G5_SKIN_DIR.'/latest/'.$match[1]; $latest_skin_url = str_replace(G5_PATH, G5_URL, $latest_skin_path); } else { $latest_skin_path = G5_THEME_PATH.'/'.G5_SKIN_DIR.'/latest/'.$match[1]; $latest_skin_url = str_replace(G5_PATH, G5_URL, $latest_skin_path); } $skin_dir = $match[1]; } else { if(G5_IS_MOBILE) { $latest_skin_path = G5_MOBILE_PATH.'/'.G5_SKIN_DIR.'/latest/'.$skin_dir; $latest_skin_url = G5_MOBILE_URL.'/'.G5_SKIN_DIR.'/latest/'.$skin_dir; } else { $latest_skin_path = G5_SKIN_PATH.'/latest/'.$skin_dir; $latest_skin_url = G5_SKIN_URL.'/latest/'.$skin_dir; } } $cache_fwrite = false; if(G5_USE_CACHE) { $cache_file = G5_DATA_PATH."/cache/latest-{$bo_table}-{$skin_dir}-{$rows}-{$subject_len}.php"; if(!file_exists($cache_file)) { $cache_fwrite = true; } else { if($cache_time > 0) { $filetime = filemtime($cache_file); if($filetime && $filetime < (G5_SERVER_TIME - 3600 * $cache_time)) { @unlink($cache_file); $cache_fwrite = true; } } if(!$cache_fwrite) include($cache_file); } } if(!G5_USE_CACHE || $cache_fwrite) { $list = array(); $sql = " select * from {$g5['board_table']} where bo_table = '{$bo_table}' "; $board = sql_fetch($sql); $bo_subject = get_text($board['bo_subject']); $tmp_write_table = $g5['write_prefix'] . $bo_table; // 게시판 테이블 전체이름 $sql = " select * from {$tmp_write_table} where ca_name='{$ca_name}' AND wr_is_comment = 0 order by wr_num limit 0, {$rows} "; $result = sql_query($sql); for ($i=0; $row = sql_fetch_array($result); $i++) { $list[$i] = get_list($row, $board, $latest_skin_url, $subject_len); } if($cache_fwrite) { $handle = fopen($cache_file, 'w'); $cache_content = "<?php\nif (!defined('_GNUBOARD_')) exit;\n\$bo_subject='".sql_escape_string($bo_subject)."';\n\$list=".var_export($list, true)."?>"; fwrite($handle, $cache_content); fclose($handle); } } ob_start(); include $latest_skin_path.'/latest.skin.php'; $content = ob_get_contents(); ob_end_clean(); return $content; } ?>
답변 2
소스가 저렇게 되어서 보기 힘들기때문에 말씀드리자면
해당 분류부분을 데이터로 가져와서 쿼리 부분을 수정해서 반영해 주셔야 합니다.
그래야 원하시는 해당 카테고리 부분을 가져올수가 있습니다.
latest.lib 파일
<?php
if (!defined('_GNUBOARD_')) exit;
// 최신글 추출
// $cache_time 캐시 갱신시간
function latest($skin_dir='', $bo_table, $rows=10, $subject_len=40, $cache_time=1, $options='')
{
global $g5;
list($bo_table, $category) = explode("|", $bo_table);
if($category) $where = " AND ca_name = '".$category."' ";
if (!$skin_dir) $skin_dir = 'basic';
if(preg_match('#^theme/(.+)$#', $skin_dir, $match)) {
if (G5_IS_MOBILE) {
$latest_skin_path = G5_THEME_MOBILE_PATH.'/'.G5_SKIN_DIR.'/latest/'.$match[1];
if(!is_dir($latest_skin_path))
$latest_skin_path = G5_THEME_PATH.'/'.G5_SKIN_DIR.'/latest/'.$match[1];
$latest_skin_url = str_replace(G5_PATH, G5_URL, $latest_skin_path);
} else {
$latest_skin_path = G5_THEME_PATH.'/'.G5_SKIN_DIR.'/latest/'.$match[1];
$latest_skin_url = str_replace(G5_PATH, G5_URL, $latest_skin_path);
}
$skin_dir = $match[1];
} else {
if(G5_IS_MOBILE) {
$latest_skin_path = G5_MOBILE_PATH.'/'.G5_SKIN_DIR.'/latest/'.$skin_dir;
$latest_skin_url = G5_MOBILE_URL.'/'.G5_SKIN_DIR.'/latest/'.$skin_dir;
} else {
$latest_skin_path = G5_SKIN_PATH.'/latest/'.$skin_dir;
$latest_skin_url = G5_SKIN_URL.'/latest/'.$skin_dir;
}
}
$cache_fwrite = false;
if(G5_USE_CACHE) {
$cache_file = G5_DATA_PATH."/cache/latest-{$bo_table}-{$skin_dir}-{$rows}-{$subject_len}.php";
if(!file_exists($cache_file)) {
$cache_fwrite = true;
} else {
if($cache_time > 0) {
$filetime = filemtime($cache_file);
if($filetime && $filetime < (G5_SERVER_TIME - 3600 * $cache_time)) {
@unlink($cache_file);
$cache_fwrite = true;
}
}
if(!$cache_fwrite)
include($cache_file);
}
}
if(!G5_USE_CACHE || $cache_fwrite) {
$list = array();
$sql = " select * from {$g5['board_table']} where bo_table = '{$bo_table}' ";
$board = sql_fetch($sql);
$bo_subject = get_text($board['bo_subject']);
$tmp_write_table = $g5['write_prefix'] . $bo_table; // 게시판 테이블 전체이름
$sql = " select * from {$tmp_write_table} where wr_is_comment = 0".$where." order by wr_num limit 0, {$rows} ";
$result = sql_query($sql);
for ($i=0; $row = sql_fetch_array($result); $i++) {
$list[$i] = get_list($row, $board, $latest_skin_url, $subject_len);
}
if($cache_fwrite) {
$handle = fopen($cache_file, 'w');
$cache_content = "<?php\nif (!defined('_GNUBOARD_')) exit;\n\$bo_subject='".sql_escape_string($bo_subject)."';\n\$list=".var_export($list, true)."?>";
fwrite($handle, $cache_content);
fclose($handle);
}
}
ob_start();
include $latest_skin_path.'/latest.skin.php';
$content = ob_get_contents();
ob_end_clean();
return $content;
}
?>
latest.skin.php 파일
<!-- CONTENT BEGIN -->
<div id="content" class="block_portfolio_4c">
<div class="inner">
<div class="block_four_columns">
<ul class="block_filtered_items">
<!-- portfolio item -->
<?php
for ($i=0; $i<count($list); $i++) {
/* 원본 이미지를 뽑아보자 - JooSung - 20150528 추가 */
$list[$i][file] =get_file($bo_table, $list[$i][wr_id]);
$file = $list[$i][file][0][path].'/'. $list[$i][file][0][file];
/* 원본 이미지를 뽑아보자 - JooSung - 20150528 추가 */
$thumb = get_list_thumbnail($bo_table, $list[$i]['wr_id'], $thumb_width, $thumb_height);
if($thumb['src']) {
$img = '<img src="'.$thumb['src'].'" width="'.$thumb_width.'" height="'.$thumb_height.'" title="'.$list[$i][subject].'" />';
} else {
$img = '<img src="'.$latest_skin_url.'/img/noimage.png" width="'.$thumb_width.'" height="'.$thumb_height.'" title="이미지 없음" />';
}
$content = cut_str(strip_tags($list[$i][wr_content]), 76);
?>
<li class="column_3 filtering_item <?php echo $list[$i][wr_link1]?"video":""?>" title="<?php echo $list[$i][ca_name]?>">
<div class="pic_wrapper">
<span class="block_general_pic">
<? if ($list[$i][wr_link1]) { ?>
<a href="<?php echo $list[$i][wr_link1]?>" title="<?php echo $list[$i][subject]?>" class="hover_1">
<? } else { ?>
<a href="<?php echo $list[$i][href]?>" title="<?php echo $list[$i][subject]?>" class="hover_1">
<? } ?>
<img width="<?php echo $thumb_width?>" height="<?php echo $thumb_height?>" src="<?php echo $thumb['src']?>" class="r_conner_pic wp-post-image" title="<?php echo $list[$i][subject]?>" />
<span class="block_hover"> </span>
</a>
</span>
</div>
<p style="padding:5px;"><strong><a href="<?php echo $list[$i][href]?>"><?php echo $list[$i][subject]?> </a></strong>
</li>
<? } ?>
<!-- portfolio item -->
</ul>
</div>
</div>
</div>
<!-- CONTENT END -->