2개 게시판에서 최신글 뽑아내고 싶어요~~

2개 게시판에서 최신글 뽑아내고 싶어요~~

QA

2개 게시판에서 최신글 뽑아내고 싶어요~~

본문

보통 최신글의 경우 1개의 게시판이나 그룹게시판에서 최신글을 뽑아오는데요.

 

그런데요. 저는 게시판 2개 또는 3개 에서 최신글을 뽑아 오고싶은데요...

 

아래 코드중 어느부분을 수정하면 가능할까요?

(랜덤 최신글   lib  코드입니다.)

 

<?
?>
//*******************************************************************************/
//랜덤게시물 추출 방법
function r_latest($skin_dir="", $bo_table, $rows=10, $subject_len=40)
{
    global $g4;

    if ($skin_dir)
        $latest_skin_path = "$g4[path]/skin/latest/$skin_dir";
    else
        $latest_skin_path = "$g4[path]/skin/latest/basic";

    $list = array();

    $sql = " select * from $g4[board_table] where bo_table = '$bo_table'";
    $board = sql_fetch($sql);

    $tmp_write_table = $g4['write_prefix'] . $bo_table; // 게시판 테이블 전체이름
    $sql = " select * from $tmp_write_table where wr_is_comment = 0 order by rand() desc limit 0, $rows ";
    //explain($sql);
    $result = sql_query($sql);
    for ($i=0; $row = sql_fetch_array($result); $i++)
        $list[$i] = get_list($row, $board, $latest_skin_path, $subject_len);
   
    ob_start();
    include "$latest_skin_path/latest.skin.php";
    $content = ob_get_contents();
    ob_end_clean();

    return $content;
}
?>​ 

이 질문에 댓글 쓰기 :

답변 2

<?
function r_latest($skin_dir='', $bo_table, $rows=10, $sublect_len=40) {
    global $g4;

    if ($skin_dir)
        $latest_skin_path = $g4['path'].'/skin/latest/'.$skin_dir;
    else
        $latest_skin_path = $g4['path'].'/skin/latest/basic';

    $arr_bo_table = explode(',', $bo_table);
    $arr_bo_table = array_filter(array_map('trim',$arr_bo_table),'strlen'); // 빈값 제거. (각 원소에 trim()을 처리후 strlen 결과가 0이면 unset함.)
    $arr_bo_table = array_unique($arr_bo_table); // 중복값 제거.
    $arr_bo_table = array_values($arr_bo_table); // 배열 인덱스 재설정.

    // $board 에 들어갈 내용을 미리 가져와 $arr_board 배열에 넣어둔다.
    $arr_board = array();
    foreach($arr_bo_table as $key=>$value) {
        if(!$arr_board[$value]) $arr_board[$value] = sql_fetch('select * from '.$g4['board_table'].' where bo_table = "'.$value.'"');
    }

    $list = array();

    if(count($arr_bo_table)>1) { // 대상 게시판이 복수일경우
        // new 테이블에서 코멘트 아닌 글만 지정갯수만큼 무작위로 가져오기.
        $sql = 'select * from '.$g4['board_new_table'].' WHERE wr_id=wr_parent and bo_table in ("'.implode('","', $arr_bo_table).'") order by rand() limit 0, '.$rows;
        $result = sql_query($sql);
        for($i=0; $new_row = sql_fetch_array($result); $i++) {
            $board = $arr_board[$new_row['bo_table']];
            $tmp_write_table = $g4['write_prefix'] . $new_row['bo_table']; // 게시판 테이블 전체이름

            // 실제 게시판 데이터 가져오기.
            $sql = ' select * from '.$tmp_write_table.' where wr_id='.$new_row['wr_id'] ;
            $row = sql_fetch($sql);
            $list[$i] = get_list($row, $board, $latest_skin_path, $subject_len);
        }

    } else { // 대상 게시판이 한개일경우 기존방법대로 직접 해당테이블에서 가져온다. 이게 성능면에서 좋을듯..
        $bo_table = $arr_bo_table[0];
        $board = $arr_board[$bo_table];
        $tmp_write_table = $g4['write_prefix'] . $bo_table; // 게시판 테이블 전체이름
        $sql = ' select * from '.$tmp_write_table.' where wr_is_comment = 0 order by rand() desc limit 0, '.$rows ;
        //explain($sql);

        $result = sql_query($sql);
        for ($i=0; $row = sql_fetch_array($result); $i++) {
            $list[$i] = get_list($row, $board, $latest_skin_path, $subject_len);
        }
    }

    ob_start();
    include $latest_skin_path.'/latest.skin.php';
    $content = ob_get_contents();
    ob_end_clean();
    return $content;
}
?>

호출방법은 기존에 bo_table 자리에 컴마로 주욱 나열해주면 됩니다. 2개 이상 가능하구요.
echo r_latest('basic', 'notice, news, gallery', 10);

다만 각 게시판별 몇개라는 제한 없이 그냥 무작위라서 글이 많은 게시판이 노출빈도도 높아지겠죠.

이런 방법이 아니라 각 게시판별로 가져오는 글의 갯수가 균등하게 한다던지 new 테이블을 이용하지 않고 한다던지 하려면 좀 바꿔야겠죠.

감사합니다~~^ ^

덕분에 썸네일 없는 최신글 형식에서는 잘 표현되어지네요.^^*


그런데요.

썸네일 있는 최신글에서는 오류가 나오더라구요...ㅡㅡ;

latest.skin.phpon line22 에 에러가 있다고 하면서요^^*

 그래서 아래 최신글 코드가 있는데요..

어떻게 하면 썸네일을 가져올수 있을가요?


<?
if (!defined("_GNUBOARD_")) exit; // 개별 페이지 접근 불가 

$thumbx = 150;
$thumby = 150;

$data_path = $g4[path]."/data/file/$bo_table";
$thumb_path = $data_path.'/latest_thumb'; // 썸네일 생성 폴더명

@mkdir($thumb_path, 0707);
@chmod($thumb_path, 0707);

?>

<table width="100%" border="0" cellspacing="0" >
	
	<tr>
		<td colspan=10>
			<table width="100%" cellpadding="0" cellspacing="0" border="0">
				<tr>
<? for($i=0; $i<count($list); $i++) {$m++;
$file_name = get_thumb_filename2($list[$i][wr_id], 0);

$thumb = $thumb_path.'/'.$list[$i][wr_id];

$file = "$g4[path]/data/file/$bo_table/".$list[$i][file][0][file];
//$destfile = $file.'_gga_gd_latest_Thumb';
$destfile = $thumb_path.'/'.$list[$i][wr_id];
	$size = @getimagesize($file);
	if(is_array($size) && !is_file($destfile)) {
		switch($size[2]) {
			case(1) :
				if(function_exists('ImageCreateFromGif')) $im = ImageCreateFromGif($file);
				break;
			case(2) :
				if(function_exists('ImageCreateFromJpeg')) $im = ImageCreateFromJpeg($file);
				break;
			case(3) :
				if(function_exists('ImageCreateFromPng')) $im = ImageCreateFromPng($file);
				break;
		}
		$fixsize = gga_image_size($size[0], $size[1], $thumbx, $thumby);
		if($im) {
			if($i==0) @exec("rm ".dirname($_SERVER[SCRIPT_FILENAME])."$g4[path]/data/file/$bo_table/*reportThumb -rf");
			if(function_exists('ImageCreateTrueColor')) $newim = ImageCreateTrueColor($fixsize[x],$fixsize[y]);
			else $newim = ImageCreate($fixsize[x],$fixsize[y]);
			if(function_exists('ImageCopyResampled')) ImageCopyResampled($newim,$im,0,0,0,0,$fixsize[x],$fixsize[y],$size[0],$size[1]);
			else ImageCopyResized($newim,$im,0,0,0,0,$fixsize[x],$fixsize[y],$size[0],$size[1]);
			ImageDestroy($im);
			ImageJpeg($newim, $destfile, 100);
			ImageDestroy($newim);
			unset($im, $newim);
		}
		$list[$i][img][x] = $fixsize[x];
		$list[$i][img][y] = $fixsize[y];
	}	else {
		if(is_file($destfile)) {
			$size = @getimagesize($destfile);
			$list[$i][img][x] = $size[0];
			$list[$i][img][y] = $size[1];
		} else {
			$file = "$latest_skin_path/img/noimage.gif";
			$size = @getimagesize($file);
			$list[$i][img][x] = $size[0];
			$list[$i][img][y] = $size[1];
		}
	}
	if(is_file($destfile)) $file = $destfile;
	if(time()-(60*60*24) <= strtotime($list[$i][wr_datetime])) $list[$i][date] = date('H:i',strtotime($list[$i][wr_datetime]));
	else $list[$i][date] = date('Y.m.d',strtotime($list[$i][wr_datetime]));

$file = str_replace('%', '%25', $file);

?>
					<td align="center" width=20%>
						<table cellpadding="0" cellspacing="0" border="0" style="padding:0px;">
                        <tr><td height=15></td></tr>
							<tr align=center>
								<td style='padding-top:0px;'>
    									<table width="10" bgcolor='#ffffff' cellpadding="3" cellspacing="0" border="0">
										<tr>
											<td align="center" valign="middle"><a href="<?=$list[$i][href]?>"><img src="<?= $file?>" width="<?=$list[$i][img][x]?>" height="<?=$list[$i][img][y]?>" border="0" title="<?=$list[$i][wr_subject]?>" style='border:1px solid #cfcfcf'></a></td>
										</tr>
									</table>
								</td>
							</tr>
							<tr>
								<td align="center" valign="middle" style='padding-top:3px;border:0px solid #777777'>
									<a href="<?=$list[$i][href]?>"><?=$list[$i][subject]?></a>
									 <!--? if ($list[$i][comment_cnt]) 
                echo " <a href=\"{$list[$i][comment_href]}\"><span style='font-family:돋움; font-size:8pt; color:#9A9A9A;'>{$list[$i][comment_cnt]}</span></a>";?!-->
									<!--?=$list[$i][icon_new]?!-->
									</td>
							</tr>
							<tr><td height=15></td></tr>
							
						</table>
					</td>
					<? if ($m%6==0){  //여기에서 줄바꾸기?></tr><tr><?}?>
<? } ?>
				</tr>
			</table>
		</td>

<? if(!count($list)) echo("<td align='center' valign='middle' height='50'><font color='gray'>등록된 사진이 없습니다.</font></td>"); ?>

	</tr>
</table>

감사합니다~~^ ^

덕분에 썸네일 없는 최신글 형식에서는 잘 표현되어지네요.^^*

 

 

 

그런데요.

썸네일 있는 최신글에서는 오류가 나오더라구요...ㅡㅡ;

latest.skin.php on line 22 에 에러가 있다고 하면서요^^*

 

그래서 아래 최신글 코드가 있는데요..

 

어떻게 하면 썸네일을 가져올수 있을가요?

 


<? 
$thumbx = 150;
$thumby = 150;
$data_path = $g4[path]."/data/file/$bo_table";
$thumb_path = $data_path.'/latest_thumb'; // 썸네일 생성 폴더명
@mkdir($thumb_path, 0707);
@chmod($thumb_path, 0707);
?>
<table width="100%" border="0" cellspacing="0" >
 
 <tr>
  <td colspan=10>
   <table width="100%" cellpadding="0" cellspacing="0" border="0">
    <tr>
<? for($i=0; $i<count($list); $i++) {$m++;
$file_name = get_thumb_filename2($list[$i][wr_id], 0);
$thumb = $thumb_path.'/'.$list[$i][wr_id];
$file = "$g4[path]/data/file/$bo_table/".$list[$i][file][0][file];
//$destfile = $file.'_gga_gd_latest_Thumb';
$destfile = $thumb_path.'/'.$list[$i][wr_id];
 $size = @getimagesize($file);
 if(is_array($size) && !is_file($destfile)) {
  switch($size[2]) {
   case(1) :
    if(function_exists('ImageCreateFromGif')) $im = ImageCreateFromGif($file);
    break;
   case(2) :
    if(function_exists('ImageCreateFromJpeg')) $im = ImageCreateFromJpeg($file);
    break;
   case(3) :
    if(function_exists('ImageCreateFromPng')) $im = ImageCreateFromPng($file);
    break;
  }
  $fixsize = gga_image_size($size[0], $size[1], $thumbx, $thumby);
  if($im) {
   if($i==0) @exec("rm ".dirname($_SERVER[SCRIPT_FILENAME])."$g4[path]/data/file/$bo_table/*reportThumb -rf");
   if(function_exists('ImageCreateTrueColor')) $newim = ImageCreateTrueColor($fixsize[x],$fixsize[y]);
   else $newim = ImageCreate($fixsize[x],$fixsize[y]);
   if(function_exists('ImageCopyResampled')) ImageCopyResampled($newim,$im,0,0,0,0,$fixsize[x],$fixsize[y],$size[0],$size[1]);
   else ImageCopyResized($newim,$im,0,0,0,0,$fixsize[x],$fixsize[y],$size[0],$size[1]);
   ImageDestroy($im);
   ImageJpeg($newim, $destfile, 100);
   ImageDestroy($newim);
   unset($im, $newim);
  }
  $list[$i][img][x] = $fixsize[x];
  $list[$i][img][y] = $fixsize[y];
 } else {
  if(is_file($destfile)) {
   $size = @getimagesize($destfile);
   $list[$i][img][x] = $size[0];
   $list[$i][img][y] = $size[1];
  } else {
   $file = "$latest_skin_path/img/noimage.gif";
   $size = @getimagesize($file);
   $list[$i][img][x] = $size[0];
   $list[$i][img][y] = $size[1];
  }
 }
 if(is_file($destfile)) $file = $destfile;
 if(time()-(60*60*24) <= strtotime($list[$i][wr_datetime])) $list[$i][date] = date('H:i',strtotime($list[$i][wr_datetime]));
 else $list[$i][date] = date('Y.m.d',strtotime($list[$i][wr_datetime]));
$file = str_replace('%', '%25', $file);
?>
     <td align="center" width=20%>
      <table cellpadding="0" cellspacing="0" border="0" style="padding:0px;">
                        <tr><td height=15></td></tr>
       <tr align=center>
        <td style='padding-top:0px;'>
             <table width="10" bgcolor='#ffffff' cellpadding="3" cellspacing="0" border="0">
          <tr>
           <td align="center" valign="middle"><a href="<?=$list[$i][href]?>"><img src="<?= $file?>" width="<?=$list[$i][img][x]?>" height="<?=$list[$i][img][y]?>" border="0" title="<?=$list[$i][wr_subject]?>" style='border:1px solid #cfcfcf'></a></td>
          </tr>
         </table>
        </td>
       </tr>
       <tr>
        <td align="center" valign="middle" style='padding-top:3px;border:0px solid #777777'>
         <a href="<?=$list[$i][href]?>"><?=$list[$i][subject]?></a>
          <!--? if ($list[$i][comment_cnt]) 
                echo " <a href=\"{$list[$i][comment_href]}\"><span style='font-family:돋움; font-size:8pt; color:#9A9A9A;'>{$list[$i][comment_cnt]}</span></a>";?!-->
         <!--?=$list[$i][icon_new]?!-->
         </td>
       </tr>
       <tr><td height=15></td></tr>
       
      </table>
     </td>
     <? if ($m%6==0){  //여기에서 줄바꾸기?></tr><tr><?}?>
<? } ?>
    </tr>
   </table>
  </td>
<? if(!count($list)) echo("<td align='center' valign='middle' height='50'><font color='gray'>등록된 사진이 없습니다.</font></td>"); ?>
 </tr>
</table>
​
 

답이 늦었습니다.
아마도 get_thumb_filename2() 함수가 없어서 난 에러는 아닐까 싶습니다.
$file_name이 쓰이는데가 없으니 그냥 그 라인은 지우셔도 상관없을듯 보입니다.
그런데 썸네일이 있어도 원본이미지를 출력하는거 같습니다. img src를 $file 대신 $thumb 쓰시는게 맞을듯해요.

답변을 작성하시기 전에 로그인 해주세요.
전체 7
QA 내용 검색

회원로그인

(주)에스아이알소프트 / 대표:홍석명 / (06211) 서울특별시 강남구 역삼동 707-34 한신인터밸리24 서관 1404호 / E-Mail: admin@sir.kr
사업자등록번호: 217-81-36347 / 통신판매업신고번호:2014-서울강남-02098호 / 개인정보보호책임자:김민섭(minsup@sir.kr)
© SIRSOFT