갤러리 최신글 랜덤 추출 방법좀 알려주세요 (소스 포함)
본문
if (!defined("_GNUBOARD_")) exit; // 개별 페이지 접근 불가
* latest.skin Gallery for Gnuboard4
* latest.skin.php
*
* Copyright 2011 Man Hyung, cho
*
* File encoding: Korean(EUC-KR)
*
*/
$image_h = 15; // 이미지 상하 간격
$is_crop = 1;
// $is_crop : 세로 높이가 $height를 넘을 때 crop 할 것인지를 결정
// 0 : crop 하지 않습니다
// 1 : 기본 crop
// 2 : 중간을 기준으로 crop
$col_width = (int)(99 / $cols);
//불당썸---------------------------------------------------------------//
$img_width = 80; //표시할 이미지의 가로사이즈
$img_height = 110; //표시할 이미지의 세로사이즈
//언샾마스트 퀄리티(썸 노이즈바지)
$filter[type] = 99;
$filter[arg1] = 100;
$filter[arg2] = 1;
$filter[arg3] = 2;
$thumb_path = $data_path.'/thumb';
$no_img = $latest_skin_path."/img/no_img.gif";
include_once("$g4[path]/lib/thumb.lib.php");
//불당썸---------------------------------------------------------------//
// $list_content = "40"; //내용길이
?>
// 제목 문자화
function prettyFont(txt) {
var str = '';
if (typeof notice == "undefined") notice = "false";
str += '<img src="<?=$latest_skin_path?>/txt2img.php?text='+encodeURIComponent(txt)+'&font='+prettyFont.font+'&size='+prettyFont.size+'&bgcolor='+prettyFont.bgColor+'&txtcolor='+prettyFont.txtColor+' border="0" />';
document.write(str);
}
function pretty1Font(txt,notice) {
var str = '';
if (typeof notice == "undefined") notice = "false";
str += '<img src="<?=$latest_skin_path?>/txt2img.php?text='+encodeURIComponent(txt)+'&font='+pretty1Font.font+'&size='+pretty1Font.size+'&bgcolor='+pretty1Font.bgColor+'&txtcolor='+pretty1Font.txtColor+' border="0" />';
document.write(str);
}
function pretty2Font(txt,notice) {
var str = '';
if (typeof notice == "undefined") notice = "false";
str += '<img src="<?=$latest_skin_path?>/txt2img.php?text='+encodeURIComponent(txt)+'&font='+pretty2Font.font+'&size='+pretty2Font.size+'&bgcolor='+pretty2Font.bgColor+'&txtcolor='+pretty2Font.txtColor+' border="0" />';
document.write(str);
}
prettyFont.size = 15;
prettyFont.bgColor = "ffffff";
prettyFont.txtColor = "777777";
pretty1Font.font = "./font/NanumGothic.ttf";
pretty1Font.size = 13;
pretty1Font.bgColor = "ffffff";
pretty1Font.txtColor = "777777";
pretty2Font.font = "./font/NanumGothicBold.ttf";
pretty2Font.size = 9;
pretty2Font.bgColor = "ffffff";
pretty2Font.txtColor = "777777";
</script>
<tr>
<td height='30' colspan="<?=$cols?>" style="padding-left:10px;">
<table width="97%" border="0" cellspacing="5" cellpadding="0">
<tr bgcolor="#FFFFFF">
<td height="22"><script type='text/javascript'>pretty2Font('· <?=$board[bo_subject]?>');</script></td>
<td align="right"> <a href='<?=$g4[bbs_path]?>/board.php?bo_table=<?=$bo_table?>'><img src="<?=$latest_skin_path?>/img/btn_more.gif" border="0"></span></a></td>
</tr>
<tr><td colspan="2" height="1" bgcolor="#c7c7c7"></td></tr>
<tr><td colspan="2" height="5" bgcolor="#FFFFFF"></td></tr>
</table>
</td>
</tr>
if ($i>0 && $i%$cols==0) {
echo "<tr><td colspan='$cols' height='$image_h'></td></tr><tr>";
}
?>
<table border="0" cellpadding="0" cellspacing="0" style="border-collapse:collapse">
<tr>
<td>
<?
//썸네일 생성
$thumfile = "";
$thumb = $thumb_path.'/'.$list[$i][wr_id];
$file = $list[$i][file][0][path] .'/'. $list[$i][file][0][file];
//$noimg = "$latest_skin_path/img/noimg.gif";
//if (preg_match("/\.(gif|jp[e]?g|png|bmp)$/i", $file) && file_exists($file)) {
//$img=thumbnail($data_path. "/".$image, $imgwidth, $imgheight, 0, 1); //썸네일이 없을경우 원본출력
$thumb = thumbnail($file, $img_width, $img_height, 0, $is_crop, 90, 0, "", $filter, $noimg); //언샾마스크추가
$edit_img = $list[$i]['wr_content'];
if (eregi("data/cheditor4[^<>]*\.(gif|jp[e]?g|png|bmp)", $edit_img, $tmp)) { // data/cheditor------
$file = $g4[path].'/' . $tmp[0]; // 파일명
$thumb=thumbnail($file, $img_width, $img_height, 0, $is_crop, 90, 0, "", $filter, $noimg); //언샾마스크추가
}
//$thumfile = "<img src='{$thumb}' width='{$img_width}' height='{$img_height}' border='0' style='border:1px #ccc solid'></a>";
echo "<table border='0' cellpadding='0' cellspacing='0'>";
echo "<tr><td width='{$img_width}' height='{$img_height}' align='center' valign='middle'>";
echo "<a href='{$list[$i]['href']}'><img src='$thumb' border='0' align='absmiddle'></a>";
echo "</td></tr>";
echo "<tr><td width='{$img_width}' align='center' valign='middle' style='padding:2px 0;>";
echo "<a href='{$list[$i]['href']}'><span style='font-size:8pt;'>{$list[$i]['subject']}</span>";
echo "</td></tr></table>";
}
else if (!file_exists($list[$i][file_image0])){ // no img
echo "<table style='border: 0px solid #e7e7e7; padding:0; margin:0; border-collapse:collapse'>";
echo "<tr><td width='{$img_width}' height='{$img_height}' align='center' valign='middle' style='border: 1px solid #e7e7e7;'>";
echo "<a href='{$list[$i]['href']}'><img src='$no_img' border='0' align='absmiddle'>";
echo "</td></tr>";
echo "<tr><td width='{$img_width}' align='center' valign='middle' style='padding:2px 0;>";
echo "<a href='{$list[$i]['href']}'><span style='font-size:8pt;'>{$list[$i]['subject']}</span>";
echo "</td></tr></table>";
}
</td>
</tr>
</table>
<?
$cnt = ($i%$cols);
for ($k=$cnt; $k<$cols && $cnt; $k++) {
echo "<td width=$col_width%> </td>";
}
?>
<? if (count($list) == 0) { echo "<td align=center height=50>게시물이 없습니다.</td>"; } ?>
</td>
</tr>
</table>
답변 1
스킨은 수정할 필요 없구요.
/lib/latest.lib.php 파일을 수정하셔야 되요.
최신글 함수 다음에 밑에 함수 붙어 넣고
최신글 불러 올때는 <?=latest_rand('스킨','게시판이름','불러올 갯수')?>
이걸 쓰시면 됩니다.
// 최신글 추출
function latest_rand($skin_dir="", $bo_table, $rows=10, $subject_len=40, $options="")
{
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() limit 0, $rows ";
// 위의 코드 보다 속도가 빠름
$sql = " select * from $tmp_write_table where wr_is_comment = 0 order by rand() 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;
}