최신글 카테고리별로 불러오기+카테고리2개이상 불러오기
왕계란님 팁 이용해서 수정했습니다(http://sir.kr/g5_tip/4129?sfl=wr_subject%7C%7Cwr_content&stx=%EC%B5%9C%EC%8B%A0%EA%B8%80+%EC%B9%B4%ED%85%8C%EA%B3%A0%EB%A6%AC)
<?=latest("theme/basic", "qa", 5, 25)?>
이게 기본적인 최신글 함수 사용법인데요,
<?=latest("theme/basic", "qa|답변", 5, 25)?>
이런 식으로 게시판 아이디 다음에 '|특정 카테고리'를 붙여 넣습니다.
그러면 뿌리는 부분에서는 끝이 났습니다.
<?=latest("theme/basic", "qa|답변,질문", 5, 25)?>
카테고리 2개 부를때는 컴마로 구문하시면 됩니다
소스가 너무 초급이고 지저분한데 깔끔하게 정리가능하시면
해주시면 감사할거같아요
lib > latest.lib.php
<?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) {
$cateArray = array();
$cateArray = explode(",", $category);
for($i=0;$i<count($cateArray);$i++){
if($i==0)
$where = " AND ca_name = '".$cateArray[$i]."' ";
else
$where .= " OR ca_name = '".$cateArray[$i]."' ";
}
}
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) {
if($category){
$cache_file = G5_DATA_PATH."/cache/latest-{$bo_table}-{$category}-{$skin_dir}-{$rows}-{$subject_len}.php";
}else{
$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='".$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("theme/basic", "qa", 5, 25)?>
이게 기본적인 최신글 함수 사용법인데요,
<?=latest("theme/basic", "qa|답변", 5, 25)?>
이런 식으로 게시판 아이디 다음에 '|특정 카테고리'를 붙여 넣습니다.
그러면 뿌리는 부분에서는 끝이 났습니다.
<?=latest("theme/basic", "qa|답변,질문", 5, 25)?>
카테고리 2개 부를때는 컴마로 구문하시면 됩니다
소스가 너무 초급이고 지저분한데 깔끔하게 정리가능하시면
해주시면 감사할거같아요
lib > latest.lib.php
<?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) {
$cateArray = array();
$cateArray = explode(",", $category);
for($i=0;$i<count($cateArray);$i++){
if($i==0)
$where = " AND ca_name = '".$cateArray[$i]."' ";
else
$where .= " OR ca_name = '".$cateArray[$i]."' ";
}
}
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) {
if($category){
$cache_file = G5_DATA_PATH."/cache/latest-{$bo_table}-{$category}-{$skin_dir}-{$rows}-{$subject_len}.php";
}else{
$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='".$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;
}
?>
댓글 9개
9년 전
[code]
list($bo_table, $category) = explode("|", $bo_table);
if($category) {
$cat = explode(",", $category);
$where = " AND ca_name IN('".implode("', '", $cat)."') ";
}
[/code]
<?=latest("theme/basic", "qa|답변,질문", 5, 25)?>
이런 식으로 넘기시면 기존에 코드를 이렇게만 바꾸시면 될 것 같네요.
테스트는 안 했습니다.
list($bo_table, $category) = explode("|", $bo_table);
if($category) {
$cat = explode(",", $category);
$where = " AND ca_name IN('".implode("', '", $cat)."') ";
}
[/code]
<?=latest("theme/basic", "qa|답변,질문", 5, 25)?>
이런 식으로 넘기시면 기존에 코드를 이렇게만 바꾸시면 될 것 같네요.
테스트는 안 했습니다.
병원에서일해요
9년 전
아 역시 in구절쓰면 되는군요 ㅎㅎ
쿼리쪽을 잘 사용못해서요
쿼리쪽을 잘 사용못해서요
ZqkWcr39s1
9년 전
감사합니다.
hoinV
9년 전
^^ 감사합니다~!!
그누랑놀자
8년 전
Warning: fopen(C:/APM_Setup/htdocs/g5/data/cache/latest-1-공지-basic-5-25.php) [function.fopen]: failed to open stream: Invalid argument in C:\APM_Setup\htdocs\g5\lib\latest.lib.php on line 85
Warning: fwrite(): supplied argument is not a valid stream resource in C:\APM_Setup\htdocs\g5\lib\latest.lib.php on line 87
Warning: fclose(): supplied argument is not a valid stream resource in C:\APM_Setup\htdocs\g5\lib\latest.lib.php on line 88
Warning: include(G5_THEME_PATH/skin/latest/basic/latest.skin.php) [function.include]: failed to open stream: No such file or directory in C:\APM_Setup\htdocs\g5\lib\latest.lib.php on line 93
Warning: include() [function.include]: Failed opening 'G5_THEME_PATH/skin/latest/basic/latest.skin.php' for inclusion (include_path='.') in C:\APM_Setup\htdocs\g5\lib\latest.lib.php on line 93
Warning: fwrite(): supplied argument is not a valid stream resource in C:\APM_Setup\htdocs\g5\lib\latest.lib.php on line 87
Warning: fclose(): supplied argument is not a valid stream resource in C:\APM_Setup\htdocs\g5\lib\latest.lib.php on line 88
Warning: include(G5_THEME_PATH/skin/latest/basic/latest.skin.php) [function.include]: failed to open stream: No such file or directory in C:\APM_Setup\htdocs\g5\lib\latest.lib.php on line 93
Warning: include() [function.include]: Failed opening 'G5_THEME_PATH/skin/latest/basic/latest.skin.php' for inclusion (include_path='.') in C:\APM_Setup\htdocs\g5\lib\latest.lib.php on line 93
8년 전
정말 고생하던건데 되네여~ 님 배려에 감사드려여
6년 전
진짜ㅠㅠㅠ 덕분에 해결했습니다ㅠ
4년 전
최신글 게시판분류인식
tomtomA
4년 전
카테고리별로 최신글을 불러왔을때 타이틀 부분에 게시판명이 뜨는데요.. 혹시 불러온 카테고리명을 타이틀로 넣을 수 있을까요..?
게시판 목록
그누보드5 팁자료실
| 번호 | 제목 | 글쓴이 | 날짜 | 조회 |
|---|---|---|---|---|
| 공지 | 3년 전 | 4429 | ||
| 2664 |
선택과집중
|
4개월 전 | 574 | |
| 2663 |
|
4개월 전 | 626 | |
| 2662 |
|
4개월 전 | 582 | |
| 2661 |
선택과집중
|
4개월 전 | 512 | |
| 2660 | 4개월 전 | 588 | ||
| 2659 |
Modify
|
4개월 전 | 654 | |
| 2658 |
선택과집중
|
4개월 전 | 416 | |
| 2657 | 4개월 전 | 452 | ||
| 2656 |
|
5개월 전 | 965 | |
| 2655 |
선택과집중
|
5개월 전 | 549 | |
| 2654 | 5개월 전 | 405 | ||
| 2653 |
선택과집중
|
5개월 전 | 591 | |
| 2652 | 5개월 전 | 398 | ||
| 2651 | 5개월 전 | 447 | ||
| 2650 |
선택과집중
|
5개월 전 | 328 | |
| 2649 |
선택과집중
|
5개월 전 | 426 | |
| 2648 | 5개월 전 | 442 | ||
| 2647 |
welcome
|
5개월 전 | 545 | |
| 2646 |
디지털홍익인간
|
5개월 전 | 453 | |
| 2645 | 5개월 전 | 469 | ||
| 2644 |
선택과집중
|
5개월 전 | 515 | |
| 2643 | 5개월 전 | 459 | ||
| 2642 | 5개월 전 | 372 | ||
| 2641 | 5개월 전 | 361 | ||
| 2640 | 5개월 전 | 394 | ||
| 2639 | 5개월 전 | 1363 | ||
| 2638 |
|
5개월 전 | 517 | |
| 2637 |
세르반데스
|
5개월 전 | 402 | |
| 2636 |
선택과집중
|
6개월 전 | 572 | |
| 2635 |
선택과집중
|
6개월 전 | 687 |
댓글 작성
댓글을 작성하시려면 로그인이 필요합니다.
로그인하기