리스트페이지에서 카테고리별로 나뉘어 보이게 하는 방법? 정보
리스트페이지에서 카테고리별로 나뉘어 보이게 하는 방법?
본문
안녕하세요.
질답 게시판과 스킨 등을 이리저리 살펴보아도 답을 얻을 수 없어 문의드립니다.
아래와 같은 방식으로 리스트페이지를 구성 중인데, 카테고리명까지는 구현했습니다만, 해당 카테고리의 내용을 뽑아 올 수가 없네요. 최근 글 스킨의 원리를 응용하면 될 것도 같은데 딱 막힌 상태랍니다.
================
카테고리명 1 ---> (구현 됨)
===============
카테고리1에 해당하는 사진들 ---> (질문 내용 : 현재는 모든 사진이 출력되고 있습니다.)
.
.
===============
카테고리명 2
===============
카테고리2에 해당하는 사진들
.
.
===============
카테고리명 3
===============
카테고리3에 해당하는 사진들
아래는 현재까지 수정한 갤러리 리스트페이지의 소스입니다.
어느 부분을 수정하면 구현이 가능할까요??
<?
if (!defined("_GNUBOARD_")) exit; // 개별 페이지 접근 불가
if (!$board[bo_1]) {
$board[bo_1] = "150";
$sql = " update $g4[board_table] set bo_1 = '$board[bo_1]', bo_1_subj = '썸네일 가로' where bo_table = '$bo_table' ";
sql_query($sql);
}
if (!$board[bo_2]) {
$board[bo_2] = "100";
$sql = " update $g4[board_table] set bo_2 = '$board[bo_2]', bo_2_subj = '썸네일 세로' where bo_table = '$bo_table' ";
sql_query($sql);
}
$mod = $board[bo_gallery_cols];
$td_width = (int)(100 / $mod);
// 선택옵션으로 인해 셀합치기가 가변적으로 변함
$colspan = 5;
if ($is_category) $colspan++;
if ($is_checkbox) $colspan++;
if ($is_good) $colspan++;
if ($is_nogood) $colspan++;
// 제목이 두줄로 표시되는 경우 이 코드를 사용해 보세요.
// <nobr style='display:block; overflow:hidden; width:000px;'>제목</nobr>
// 불당썸을 include
include_once("$g4[path]/lib/thumb.lib.php");
// 카테고리 불러오기
$sql = " SELECT * FROM `g4_board` WHERE bo_table = '$bo_table' ORDER BY `bo_category_list` ";
$result = mysql_query($sql);
while ($cat=mysql_fetch_array($result)) {
$cat1 = explode("|", $cat[bo_category_list]);
if ($cat1[0]) {
?>
<style type="text/css">
.board_button { clear:both; margin:10px 0 0 0;}
.board_page { clear:both; text-align:center; padding:3px 0 0 0; border-top:1px solid #D8D8D8;}
.board_page a:link { color:#777;}
.board_search { text-align:center; margin:10px 0 0 0;}
.board_search .stx { height:21px; border-right:1px solid #D8D8D8; border-bottom:1px solid #D8D8D8;}
</style>
<script type="text/javascript" src="<?=$g4[path]?>/js/b4.common.js"></script>
<table width="100%" border="0" cellspacing="5" cellpadding="0">
<tr>
<td height="1" bgcolor="#CCCCCC"></td>
</tr>
<? for ($c=0; $c<count($cat1); $c++) { ?>
<tr>
<td style="padding-left:10">
<!-- 카테고리 타이틀 -->
<?=$cat1[$c]?>
</td>
</tr>
<tr>
<td style="padding-left:10">
<!-- 이미지 목록 -->
<table width="100%" cellpadding="0" cellspacing="0">
<tr align="center">
<?
for ($i=0; $i<count($list); $i++)
{
$e_text = array("(",")"); //괄호 표시
$list[$i][comment_cnt] = str_replace($e_text, "", $list[$i][comment_cnt]); //괄호 표시 변환으로 삭제
// 이미지가 있으면 썸을 생성, 아니면 pass~!
if ($list[$i][file][0][file])
{
$file = $list[$i][file][0][path] .'/'. $list[$i][file][0][file];
$img = "<div style='width:{$img2_width}px; padding:4px;'><a href=\"{$list[$i][href]}\"><img src='" . thumbnail($file,$board[bo_1],$board[bo_2],false,1,100) . "' style='border:5px solid #eaeaea;'></a></div>";
}
else
{
$img = "<div style='width:{$img2_width}px; height:{$img2_height}px; border:0px solid #FFFFFF;padding:4px;'></div>";
}
if ($i && $i%$mod==0)
echo "</tr><tr><td colspan='{$mod}' height='1' bgcolor='#e8e8e8';\"></td></tr><tr>";
echo "<td width='{$td_width}%' valign=top style='word-break:break-all;'>";
echo "<table width='100%' border='0' cellspacing='0' cellpadding='0'>";
echo "<tr><td height='5'></td></tr>";
echo "<tr><td align=center>";
echo "$img";
echo "</td></tr>";
echo "<tr><td align=center style='padding-top:3px;padding-bottom:5px;'><div style='width:150px;'>";
// if ($is_category) {
// echo "<font class='color_category'>[".$list[$i][ca_name]."]</font><br>"; }
echo "<a href='".$list[$i][href]."'>".$list[$i][subject]."</a>";
// if ($list[$i][comment_cnt])
// echo " <font style='font:normal 11px Tahoma; color:#ff8700'>{$list[$i][comment_cnt]}</font>";
// echo " " . $list[$i][icon_new];
echo "</div></td></tr>";
echo "<tr><td align=center height='0'>";
// echo "<font style='font:normal 11px 돋움, Dotum; color:#777777;'>{$list[$i][wr_name]}</font>";
// echo "<br />";
// echo "<font style='font:normal 11px Tahoma; color:#c7c7c7'>{$list[$i][datetime]}</font>";
if ($is_checkbox) {
echo "<br /><input type=checkbox name=chk_wr_id[] value='".$list[$i][wr_id]."'> "; }
echo "</td></tr>";
echo "</table><br></td>\n";
}
// 나머지 td
$cnt = $i%$mod;
if ($cnt)
for ($i=$cnt; $i<$mod; $i++)
echo "<td width='{$td_width}%'> </td>";
echo "</tr>";
//echo "<tr><td colspan='{$mod}' height='1' bgcolor=000000 left;\"></td></tr>";
if (count($list) == 0) { echo "<tr><td colspan='$mod' height=100 align=center>게시물이 없습니다.</td></tr>"; }
?>
</table>
<!-- //이미지 목록 -->
</td>
</tr>
<tr>
<td height="1" bgcolor="#CCCCCC"></td>
</tr>
<? } ?>
</table>
<? } else { ?>
<? } ?>
<? } ?>
<table border=0 width="<?=$width?>" cellspacing="0" cellpadding="0" align="center">
<tr height="25"><td>
<div style="clear:both; margin-top:7px; height:31px;">
<div style="float:left;">
<? if ($list_href) { ?>
<a href="<?=$list_href?>"><img src="<?=$board_skin_path?>/img/btn_list.gif" align=absmiddle></a>
<? } ?>
<? if ($is_checkbox) { ?>
<a href="javascript:select_delete();"><img src="<?=$board_skin_path?>/img/btn_selDel.gif" align=absmiddle></a>
<a href="javascript:select_copy('copy');"><img src="<?=$board_skin_path?>/img/btn_selCopy.gif" align=absmiddle></a>
<a href="javascript:select_copy('move');"><img src="<?=$board_skin_path?>/img/btn_selMove.gif" align=absmiddle></a>
<? } ?>
</div>
<div style="float:right;">
<? if ($write_href) { ?><a href="<?=$write_href?>"><img src="<?=$board_skin_path?>/img/btn_write.gif" border="0"></a><? } ?>
</div>
</div>
</td><tr></tr></table>
<!-- 페이지 -->
<div style="text-align:center; line-height:30px; clear:both; margin:5px 0 10px 0; padding:5px 0; font-family:gulim;">
<? if ($prev_part_href) { echo "<a href='$prev_part_href'><img src='$board_skin_path/img/page_search_prev.gif' border=0 align=absmiddle title='이전검색'></a>"; } ?>
<?
// 기본으로 넘어오는 페이지를 아래와 같이 변환하여 이미지로도 출력할 수 있습니다.
//echo $write_pages;
$write_pages = str_replace("처음", "<img src='$board_skin_path/img/page_begin.gif' border='0' align='absmiddle' title='처음'>", $write_pages);
$write_pages = str_replace("이전", "<img src='$board_skin_path/img/page_prev.gif' border='0' align='absmiddle' title='이전'>", $write_pages);
$write_pages = str_replace("다음", "<img src='$board_skin_path/img/page_next.gif' border='0' align='absmiddle' title='다음'>", $write_pages);
$write_pages = str_replace("맨끝", "<img src='$board_skin_path/img/page_end.gif' border='0' align='absmiddle' title='맨끝'>", $write_pages);
$write_pages = preg_replace("/<span>([0-9]*)<\/span>/", "<b><span style=\"color:#B3B3B3; font-size:12px;\">$1</span></b>", $write_pages);
$write_pages = preg_replace("/<b>([0-9]*)<\/b>/", "<b><span style=\"color:#4D6185; font-size:12px; text-decoration:underline;\">$1</span></b>", $write_pages);
?>
<?=$write_pages?>
<? if ($next_part_href) { echo "<a href='$next_part_href'><img src='$board_skin_path/img/page_search_next.gif' border=0 align=absmiddle title='다음검색'></a>"; } ?>
</div>
<script type="text/javascript">
if ('<?=$sca?>') document.fcategory.sca.value = '<?=$sca?>';
if ('<?=$stx?>') {
document.fsearch.sfl.value = '<?=$sfl?>';
if ('<?=$sop?>' == 'and')
document.fsearch.sop[0].checked = true;
if ('<?=$sop?>' == 'or')
document.fsearch.sop[1].checked = true;
} else {
document.fsearch.sop[0].checked = true;
}
</script>
<? if ($is_checkbox) { ?>
<script type="text/javascript">
function all_checked(sw) {
var f = document.fboardlist;
for (var i=0; i<f.length; i++) {
if (f.elements[i].name == "chk_wr_id[]")
f.elements[i].checked = sw;
}
}
function check_confirm(str) {
var f = document.fboardlist;
var chk_count = 0;
for (var i=0; i<f.length; i++) {
if (f.elements[i].name == "chk_wr_id[]" && f.elements[i].checked)
chk_count++;
}
if (!chk_count) {
alert(str + "할 게시물을 하나 이상 선택하세요.");
return false;
}
return true;
}
// 선택한 게시물 삭제
function select_delete() {
var f = document.fboardlist;
str = "삭제";
if (!check_confirm(str))
return;
if (!confirm("선택한 게시물을 정말 "+str+" 하시겠습니까?\n\n한번 "+str+"한 자료는 복구할 수 없습니다"))
return;
f.action = "./delete_all.php";
f.submit();
}
// 선택한 게시물 복사 및 이동
function select_copy(sw) {
var f = document.fboardlist;
if (sw == "copy")
str = "복사";
else
str = "이동";
if (!check_confirm(str))
return;
var sub_win = window.open("", "move", "left=50, top=50, width=500, height=550, scrollbars=1");
f.sw.value = sw;
f.target = "move";
f.action = "./move.php";
f.submit();
}
</script>
<? } ?>
<!-- 게시판 목록 끝 -->
질답 게시판과 스킨 등을 이리저리 살펴보아도 답을 얻을 수 없어 문의드립니다.
아래와 같은 방식으로 리스트페이지를 구성 중인데, 카테고리명까지는 구현했습니다만, 해당 카테고리의 내용을 뽑아 올 수가 없네요. 최근 글 스킨의 원리를 응용하면 될 것도 같은데 딱 막힌 상태랍니다.
================
카테고리명 1 ---> (구현 됨)
===============
카테고리1에 해당하는 사진들 ---> (질문 내용 : 현재는 모든 사진이 출력되고 있습니다.)
.
.
===============
카테고리명 2
===============
카테고리2에 해당하는 사진들
.
.
===============
카테고리명 3
===============
카테고리3에 해당하는 사진들
아래는 현재까지 수정한 갤러리 리스트페이지의 소스입니다.
어느 부분을 수정하면 구현이 가능할까요??
<?
if (!defined("_GNUBOARD_")) exit; // 개별 페이지 접근 불가
if (!$board[bo_1]) {
$board[bo_1] = "150";
$sql = " update $g4[board_table] set bo_1 = '$board[bo_1]', bo_1_subj = '썸네일 가로' where bo_table = '$bo_table' ";
sql_query($sql);
}
if (!$board[bo_2]) {
$board[bo_2] = "100";
$sql = " update $g4[board_table] set bo_2 = '$board[bo_2]', bo_2_subj = '썸네일 세로' where bo_table = '$bo_table' ";
sql_query($sql);
}
$mod = $board[bo_gallery_cols];
$td_width = (int)(100 / $mod);
// 선택옵션으로 인해 셀합치기가 가변적으로 변함
$colspan = 5;
if ($is_category) $colspan++;
if ($is_checkbox) $colspan++;
if ($is_good) $colspan++;
if ($is_nogood) $colspan++;
// 제목이 두줄로 표시되는 경우 이 코드를 사용해 보세요.
// <nobr style='display:block; overflow:hidden; width:000px;'>제목</nobr>
// 불당썸을 include
include_once("$g4[path]/lib/thumb.lib.php");
// 카테고리 불러오기
$sql = " SELECT * FROM `g4_board` WHERE bo_table = '$bo_table' ORDER BY `bo_category_list` ";
$result = mysql_query($sql);
while ($cat=mysql_fetch_array($result)) {
$cat1 = explode("|", $cat[bo_category_list]);
if ($cat1[0]) {
?>
<style type="text/css">
.board_button { clear:both; margin:10px 0 0 0;}
.board_page { clear:both; text-align:center; padding:3px 0 0 0; border-top:1px solid #D8D8D8;}
.board_page a:link { color:#777;}
.board_search { text-align:center; margin:10px 0 0 0;}
.board_search .stx { height:21px; border-right:1px solid #D8D8D8; border-bottom:1px solid #D8D8D8;}
</style>
<script type="text/javascript" src="<?=$g4[path]?>/js/b4.common.js"></script>
<table width="100%" border="0" cellspacing="5" cellpadding="0">
<tr>
<td height="1" bgcolor="#CCCCCC"></td>
</tr>
<? for ($c=0; $c<count($cat1); $c++) { ?>
<tr>
<td style="padding-left:10">
<!-- 카테고리 타이틀 -->
<?=$cat1[$c]?>
</td>
</tr>
<tr>
<td style="padding-left:10">
<!-- 이미지 목록 -->
<table width="100%" cellpadding="0" cellspacing="0">
<tr align="center">
<?
for ($i=0; $i<count($list); $i++)
{
$e_text = array("(",")"); //괄호 표시
$list[$i][comment_cnt] = str_replace($e_text, "", $list[$i][comment_cnt]); //괄호 표시 변환으로 삭제
// 이미지가 있으면 썸을 생성, 아니면 pass~!
if ($list[$i][file][0][file])
{
$file = $list[$i][file][0][path] .'/'. $list[$i][file][0][file];
$img = "<div style='width:{$img2_width}px; padding:4px;'><a href=\"{$list[$i][href]}\"><img src='" . thumbnail($file,$board[bo_1],$board[bo_2],false,1,100) . "' style='border:5px solid #eaeaea;'></a></div>";
}
else
{
$img = "<div style='width:{$img2_width}px; height:{$img2_height}px; border:0px solid #FFFFFF;padding:4px;'></div>";
}
if ($i && $i%$mod==0)
echo "</tr><tr><td colspan='{$mod}' height='1' bgcolor='#e8e8e8';\"></td></tr><tr>";
echo "<td width='{$td_width}%' valign=top style='word-break:break-all;'>";
echo "<table width='100%' border='0' cellspacing='0' cellpadding='0'>";
echo "<tr><td height='5'></td></tr>";
echo "<tr><td align=center>";
echo "$img";
echo "</td></tr>";
echo "<tr><td align=center style='padding-top:3px;padding-bottom:5px;'><div style='width:150px;'>";
// if ($is_category) {
// echo "<font class='color_category'>[".$list[$i][ca_name]."]</font><br>"; }
echo "<a href='".$list[$i][href]."'>".$list[$i][subject]."</a>";
// if ($list[$i][comment_cnt])
// echo " <font style='font:normal 11px Tahoma; color:#ff8700'>{$list[$i][comment_cnt]}</font>";
// echo " " . $list[$i][icon_new];
echo "</div></td></tr>";
echo "<tr><td align=center height='0'>";
// echo "<font style='font:normal 11px 돋움, Dotum; color:#777777;'>{$list[$i][wr_name]}</font>";
// echo "<br />";
// echo "<font style='font:normal 11px Tahoma; color:#c7c7c7'>{$list[$i][datetime]}</font>";
if ($is_checkbox) {
echo "<br /><input type=checkbox name=chk_wr_id[] value='".$list[$i][wr_id]."'> "; }
echo "</td></tr>";
echo "</table><br></td>\n";
}
// 나머지 td
$cnt = $i%$mod;
if ($cnt)
for ($i=$cnt; $i<$mod; $i++)
echo "<td width='{$td_width}%'> </td>";
echo "</tr>";
//echo "<tr><td colspan='{$mod}' height='1' bgcolor=000000 left;\"></td></tr>";
if (count($list) == 0) { echo "<tr><td colspan='$mod' height=100 align=center>게시물이 없습니다.</td></tr>"; }
?>
</table>
<!-- //이미지 목록 -->
</td>
</tr>
<tr>
<td height="1" bgcolor="#CCCCCC"></td>
</tr>
<? } ?>
</table>
<? } else { ?>
<? } ?>
<? } ?>
<table border=0 width="<?=$width?>" cellspacing="0" cellpadding="0" align="center">
<tr height="25"><td>
<div style="clear:both; margin-top:7px; height:31px;">
<div style="float:left;">
<? if ($list_href) { ?>
<a href="<?=$list_href?>"><img src="<?=$board_skin_path?>/img/btn_list.gif" align=absmiddle></a>
<? } ?>
<? if ($is_checkbox) { ?>
<a href="javascript:select_delete();"><img src="<?=$board_skin_path?>/img/btn_selDel.gif" align=absmiddle></a>
<a href="javascript:select_copy('copy');"><img src="<?=$board_skin_path?>/img/btn_selCopy.gif" align=absmiddle></a>
<a href="javascript:select_copy('move');"><img src="<?=$board_skin_path?>/img/btn_selMove.gif" align=absmiddle></a>
<? } ?>
</div>
<div style="float:right;">
<? if ($write_href) { ?><a href="<?=$write_href?>"><img src="<?=$board_skin_path?>/img/btn_write.gif" border="0"></a><? } ?>
</div>
</div>
</td><tr></tr></table>
<!-- 페이지 -->
<div style="text-align:center; line-height:30px; clear:both; margin:5px 0 10px 0; padding:5px 0; font-family:gulim;">
<? if ($prev_part_href) { echo "<a href='$prev_part_href'><img src='$board_skin_path/img/page_search_prev.gif' border=0 align=absmiddle title='이전검색'></a>"; } ?>
<?
// 기본으로 넘어오는 페이지를 아래와 같이 변환하여 이미지로도 출력할 수 있습니다.
//echo $write_pages;
$write_pages = str_replace("처음", "<img src='$board_skin_path/img/page_begin.gif' border='0' align='absmiddle' title='처음'>", $write_pages);
$write_pages = str_replace("이전", "<img src='$board_skin_path/img/page_prev.gif' border='0' align='absmiddle' title='이전'>", $write_pages);
$write_pages = str_replace("다음", "<img src='$board_skin_path/img/page_next.gif' border='0' align='absmiddle' title='다음'>", $write_pages);
$write_pages = str_replace("맨끝", "<img src='$board_skin_path/img/page_end.gif' border='0' align='absmiddle' title='맨끝'>", $write_pages);
$write_pages = preg_replace("/<span>([0-9]*)<\/span>/", "<b><span style=\"color:#B3B3B3; font-size:12px;\">$1</span></b>", $write_pages);
$write_pages = preg_replace("/<b>([0-9]*)<\/b>/", "<b><span style=\"color:#4D6185; font-size:12px; text-decoration:underline;\">$1</span></b>", $write_pages);
?>
<?=$write_pages?>
<? if ($next_part_href) { echo "<a href='$next_part_href'><img src='$board_skin_path/img/page_search_next.gif' border=0 align=absmiddle title='다음검색'></a>"; } ?>
</div>
<script type="text/javascript">
if ('<?=$sca?>') document.fcategory.sca.value = '<?=$sca?>';
if ('<?=$stx?>') {
document.fsearch.sfl.value = '<?=$sfl?>';
if ('<?=$sop?>' == 'and')
document.fsearch.sop[0].checked = true;
if ('<?=$sop?>' == 'or')
document.fsearch.sop[1].checked = true;
} else {
document.fsearch.sop[0].checked = true;
}
</script>
<? if ($is_checkbox) { ?>
<script type="text/javascript">
function all_checked(sw) {
var f = document.fboardlist;
for (var i=0; i<f.length; i++) {
if (f.elements[i].name == "chk_wr_id[]")
f.elements[i].checked = sw;
}
}
function check_confirm(str) {
var f = document.fboardlist;
var chk_count = 0;
for (var i=0; i<f.length; i++) {
if (f.elements[i].name == "chk_wr_id[]" && f.elements[i].checked)
chk_count++;
}
if (!chk_count) {
alert(str + "할 게시물을 하나 이상 선택하세요.");
return false;
}
return true;
}
// 선택한 게시물 삭제
function select_delete() {
var f = document.fboardlist;
str = "삭제";
if (!check_confirm(str))
return;
if (!confirm("선택한 게시물을 정말 "+str+" 하시겠습니까?\n\n한번 "+str+"한 자료는 복구할 수 없습니다"))
return;
f.action = "./delete_all.php";
f.submit();
}
// 선택한 게시물 복사 및 이동
function select_copy(sw) {
var f = document.fboardlist;
if (sw == "copy")
str = "복사";
else
str = "이동";
if (!check_confirm(str))
return;
var sub_win = window.open("", "move", "left=50, top=50, width=500, height=550, scrollbars=1");
f.sw.value = sw;
f.target = "move";
f.action = "./move.php";
f.submit();
}
</script>
<? } ?>
<!-- 게시판 목록 끝 -->
댓글 전체

왠지 낯설지 않은 질문이네요.. (그때도 답을 남겨드렸던것 같은데.. ^^;)
일단 list.skin.php에서 처리하는 방식은 일종의 '땜빵'입니다.
list.php에서 이미 paging 처리되어 넘어온 게시물에 대해서만 카테고리별로 나누어 보여주는 것이라서요.
그래도 원하신다면,
list for 루프 시작할때,
if ($list[$i]['ca_name'] != $cat1[$c]) continue;
를 넣으셔서, 해당 카테고리가 아니면 출력하지 않게 하시는 방법이 있습니다.
일단 list.skin.php에서 처리하는 방식은 일종의 '땜빵'입니다.
list.php에서 이미 paging 처리되어 넘어온 게시물에 대해서만 카테고리별로 나누어 보여주는 것이라서요.
그래도 원하신다면,
list for 루프 시작할때,
if ($list[$i]['ca_name'] != $cat1[$c]) continue;
를 넣으셔서, 해당 카테고리가 아니면 출력하지 않게 하시는 방법이 있습니다.

감사합니다.
아직 다른 문제가 남아있긴 하지만, 덕분에 일단 해결되었습니다.
그런데, 이와 관련해서는 저는 처음 질문을 올린 것이랍니다.
검색을 하다보니, 거의 동일한 질문을 하신 분이 계시더군요.
그래서, 질문의 형식을 차용하기는 했습니다...^^;
아직 다른 문제가 남아있긴 하지만, 덕분에 일단 해결되었습니다.
그런데, 이와 관련해서는 저는 처음 질문을 올린 것이랍니다.
검색을 하다보니, 거의 동일한 질문을 하신 분이 계시더군요.
그래서, 질문의 형식을 차용하기는 했습니다...^^;

아, 그랬군요.. ^^;
질문 형식이 눈에 익었던것 같습니다. ^^
질문 형식이 눈에 익었던것 같습니다. ^^