연혁스킨을 만들어 보는 중인데 에러가 나서 질문 드립니다.
본문
1. 연도 2010, 2011, 2012 ... 는 카테고리를 이용 합니다.
2. 게시물의 내용을 읽어와서 아래 순서로 뿌려 줍니다.
[카테고리1] : 첫번째 카테고리의 게시물을 wr_1 기준 내림차순으로 출력 합니다.
- [wr_1 : 12월] [wr_content : 내용]
- [wr_1 : 11월] [wr_content : 내용]
- [wr_1 : 10월] [wr_content : 내용]
[카테고리2] : 두번째 카테고리의 게시물을 wr_1 기준 내림차순으로 출력 합니다.
- [wr_1 : 12월] [wr_content : 내용]
- [wr_1 : 11월] [wr_content : 내용]
- [wr_1 : 10월] [wr_content : 내용]
[카테고리3] : 세번째 카테고리의 게시물을 wr_1 기준 오름차순으로 출력 합니다. [wr_1 : 월]
- [wr_1 : 12월] [wr_content : 내용]
- [wr_1 : 11월] [wr_content : 내용]
- [wr_1 : 10월] [wr_content : 내용]
[wr_content : 내용] 의 경우 이미지가 첨부되는 경우 이미지를 가로200px로 보여주고 이미지 옆에 글씨가 나란히 정렬되게 해주세요.
이와 같은 내용으로 챗GPT를 통해 여러차례 소스 수정을 했는데요.
아래와 같은 소스를 얻었습니다.
그런데 적용을 하면 흰색화면이 보이면서 무한로딩이 되네요.
일단 화면이 뜨기라도 하면 오류 부분을 수정할텐데 화면 자체가 안뜨고 있어서요.
어느 부분이 잘못된 것일까요?
<?php
if (!defined('_GNUBOARD_')) exit; // 개별 페이지 접근 불가
// --- ? 필수 함수 및 변수 초기화 ---
// (1) wr_content 이미지 및 텍스트 포맷 함수
function format_history_content($content) {
return preg_replace_callback('/<img[^>]+src="([^"]+)"[^>]*>/i', function($matches) {
$src = $matches[1];
return '<img src="'.esc_url($src).'" style="max-width:200px;height:auto;margin-right:15px;">';
}, $content);
}
// (2) 기본 스타일 로드
add_stylesheet('<link rel="stylesheet" href="'.esc_url($board_skin_url).'/style.css">', 0);
// (3) 기본 변수 설정
$width = isset($width) ? $width : '100%';
// --- ✅ 데이터베이스 조회 & 오류 처리 ---
if (!isset($write_table) || !$write_table) {
echo '<p style="color:red;">Error: $write_table이 설정되지 않았습니다.</p>';
return;
}
$sql = "SELECT * FROM {$write_table} WHERE wr_is_comment = 0 ORDER BY ca_name ASC, CAST(wr_1 AS UNSIGNED) ASC, wr_num ASC";
$result = sql_query($sql, false);
if (!$result) {
echo '<p style="color:red;">SQL 실행 오류: '.sql_error().'</p>';
return;
}
// --- ? 데이터를 연도별로 그룹화 ---
$history_data = [];
while ($row = sql_fetch_array($result)) {
$year = trim($row['ca_name']);
$month = trim($row['wr_1']);
$content = $row['wr_content'];
$history_data[$year][] = [
'month' => $month,
'content' => $content
];
}
?>
<div id="bo_list" style="width:<?= esc_attr($width) ?>;">
<?php if ($is_category) { ?>
<nav id="bo_cate">
<h2><?= esc_html($board['bo_subject']) ?> 카테고리</h2>
<ul id="bo_cate_ul">
<?= $category_option ?>
</ul>
</nav>
<?php } ?>
<form name="fboardlist" id="fboardlist" action="<?= G5_BBS_URL ?>/board_list_update.php" method="post" onsubmit="return fboardlist_submit(this);">
<input type="hidden" name="bo_table" value="<?= esc_attr($bo_table) ?>">
<input type="hidden" name="sfl" value="<?= esc_attr($sfl) ?>">
<input type="hidden" name="stx" value="<?= esc_attr($stx) ?>">
<input type="hidden" name="spt" value="<?= esc_attr($spt) ?>">
<input type="hidden" name="sca" value="<?= esc_attr($sca) ?>">
<input type="hidden" name="sst" value="<?= esc_attr($sst) ?>">
<input type="hidden" name="sod" value="<?= esc_attr($sod) ?>">
<input type="hidden" name="page" value="<?= esc_attr($page) ?>">
<input type="hidden" name="sw" value="">
<div id="bo_btn_top">
<div id="bo_list_total">
<span>Total <?= number_format($total_count) ?>건</span>
<?= esc_html($page) ?> 페이지
</div>
<ul class="btn_bo_user">
<?php if ($admin_href) { ?>
<li><a href="<?= esc_url($admin_href) ?>" class="btn_admin btn"><i class="fa fa-cog fa-spin fa-fw"></i></a></li>
<?php }
if ($rss_href) { ?>
<li><a href="<?= esc_url($rss_href) ?>" class="btn_b01 btn"><i class="fa fa-rss"></i></a></li>
<?php } ?>
<li><button type="button" class="btn_bo_sch btn_b01 btn"><i class="fa fa-search"></i></button></li>
<?php if ($write_href) { ?>
<li><a href="<?= esc_url($write_href) ?>" class="btn_b01 btn"><i class="fa fa-pencil"></i></a></li>
<?php }
if ($is_admin == 'super' || $is_auth) { ?>
<li><button type="button" class="btn_more_opt is_list_btn btn_b01 btn"><i class="fa fa-ellipsis-v"></i></button>
<?php if ($is_checkbox) { ?>
<ul class="more_opt is_list_btn">
<li><button type="submit" name="btn_submit" value="선택삭제" onclick="document.pressed=this.value">선택삭제</button></li>
<li><button type="submit" name="btn_submit" value="선택복사" onclick="document.pressed=this.value">선택복사</button></li>
<li><button type="submit" name="btn_submit" value="선택이동" onclick="document.pressed=this.value">선택이동</button></li>
</ul>
<?php } ?>
</li>
<?php } ?>
</ul>
</div>
<div class="tbl_head01 tbl_wrap">
<div class="history-wrap">
<?php foreach ($history_data as $year => $items): ?>
<h2 class="title_h2"><?= esc_html($year) ?></h2>
<div class="container">
<?php foreach ($items as $item): ?>
<div class="row pd-50 mb-10">
<div class="col-lg-1"></div>
<div class="col-lg-1 title_h3"><?= esc_html($item['month']) ?></div>
<div class="col-lg-10 title_h2">
<div class="text_lg history-item">
<?= format_history_content($item['content']) ?>
</div>
</div>
</div>
<?php endforeach; ?>
</div>
<div class="container mt-50">
<div style="border-top:1px dashed #cacaca;width:100%;margin:30px 0;"></div>
</div>
<?php endforeach; ?>
</div>
</div>
<?= $write_pages; ?>
<?php if ($list_href || $is_checkbox || $write_href) { ?>
<div class="bo_fx">
<?php if ($list_href || $write_href) { ?>
<ul class="btn_bo_user">
<?php if ($admin_href) { ?>
<li><a href="<?= esc_url($admin_href) ?>" class="btn_admin btn"><i class="fa fa-cog fa-fw"></i></a></li>
<?php }
if ($rss_href) { ?>
<li><a href="<?= esc_url($rss_href) ?>" class="btn_b01 btn"><i class="fa fa-rss"></i></a></li>
<?php }
if ($write_href) { ?>
<li><a href="<?= esc_url($write_href) ?>" class="btn_b01 btn"><i class="fa fa-pencil"></i></a></li>
<?php } ?>
</ul>
<?php } ?>
</div>
<?php } ?>
</form>
<div class="bo_sch_wrap">
<fieldset class="bo_sch">
<h3>검색</h3>
<form name="fsearch" method="get">
<input type="hidden" name="bo_table" value="<?= esc_attr($bo_table) ?>">
<input type="hidden" name="sca" value="<?= esc_attr($sca) ?>">
<input type="hidden" name="sop" value="and">
<select name="sfl"><?= get_board_sfl_select_options($sfl) ?></select>
<input type="text" name="stx" value="<?= esc_attr(stripslashes($stx)) ?>" required placeholder="검색어를 입력해주세요">
<button type="submit" class="sch_btn"><i class="fa fa-search"></i></button>
<button type="button" class="bo_sch_cls"><i class="fa fa-times"></i></button>
</form>
</fieldset>
<div class="bo_sch_bg"></div>
</div>
</div>
<?php if ($is_checkbox) { ?>
<noscript>
<p>자바스크립트를 사용하지 않는 경우<br>별도 확인 없이 바로 삭제 처리됩니다.</p>
</noscript>
<script>
function all_checked(sw) { /* ... */ }
function fboardlist_submit(f) { /* ... */ }
function select_copy(sw) { /* ... */ }
jQuery(function($){
$(".btn_bo_sch").click(() => $(".bo_sch_wrap").toggle());
$(".bo_sch_bg, .bo_sch_cls").click(() => $(".bo_sch_wrap").hide());
$(".btn_more_opt.is_list_btn").click(e => {
e.stopPropagation();
$(".more_opt.is_list_btn").toggle();
});
$(document).click(e => {
if (!$(e.target).closest('.is_list_btn').length) {
$(".more_opt.is_list_btn").hide();
}
});
});
</script>
<?php } ?>
답변 1
아래의 내용을 한번 참고 해보시겠어요..
<?php
if (!defined('_GNUBOARD_')) exit; // 개별 페이지 접근 불가
// --- 필수 함수 및 변수 초기화 ---
// (1) wr_content 이미지 및 텍스트 포맷 함수
function format_history_content($content) {
if (!$content) return '';
// HTML 태그 허용하면서 이미지 크기만 조정
$content = preg_replace_callback('/<img[^>]+>/i', function($matches) {
$img_tag = $matches[0];
// 이미 style이 있는 경우 제거하고 새로 추가
$img_tag = preg_replace('/style="[^"]*"/i', '', $img_tag);
$img_tag = str_replace('<img', '<img style="max-width:200px;height:auto;margin-right:15px;vertical-align:top;"', $img_tag);
return $img_tag;
}, $content);
return $content;
}
// (2) 기본 변수 설정
$width = isset($width) ? $width : '100%';
// --- 데이터베이스 조회 & 오류 처리 ---
if (!isset($write_table) || !$write_table) {
echo '<div class="error-message">테이블 정보가 없습니다.</div>';
return;
}
// SQL 쿼리 수정 - 더 안전하게
$sql = "SELECT wr_id, ca_name, wr_1, wr_content, wr_datetime
FROM {$write_table}
WHERE wr_is_comment = 0
ORDER BY ca_name ASC, CAST(wr_1 AS UNSIGNED) DESC, wr_datetime DESC";
$result = sql_query($sql);
if (!$result) {
echo '<div class="error-message">데이터를 불러올 수 없습니다.</div>';
return;
}
// --- 데이터를 연도별로 그룹화 ---
$history_data = array();
while ($row = sql_fetch_array($result)) {
$year = trim($row['ca_name']);
$month = trim($row['wr_1']);
$content = $row['wr_content'];
if (!$year) continue; // 빈 카테고리는 건너뛰기
$history_data[$year][] = array(
'month' => $month,
'content' => $content
);
}
// 연도별 정렬 (최신 연도가 위로)
krsort($history_data);
?>
<style>
.history-wrap {
width: 100%;
max-width: 1200px;
margin: 0 auto;
padding: 20px;
}
.history-wrap .title_h2 {
font-size: 2em;
font-weight: bold;
color: #333;
margin: 40px 0 20px 0;
padding-bottom: 10px;
border-bottom: 3px solid #007bff;
}
.history-wrap .container {
margin-bottom: 30px;
}
.history-wrap .row {
display: flex;
align-items: flex-start;
margin-bottom: 20px;
padding: 15px 0;
}
.history-wrap .col-lg-1 {
flex: 0 0 8.333333%;
}
.history-wrap .col-lg-10 {
flex: 0 0 83.333333%;
padding-left: 15px;
}
.history-wrap .title_h3 {
font-size: 1.2em;
font-weight: bold;
color: #666;
text-align: center;
}
.history-wrap .history-item {
line-height: 1.6;
color: #444;
}
.history-wrap .history-item img {
float: left;
margin-right: 15px;
margin-bottom: 10px;
}
.history-wrap .divider {
border-top: 1px dashed #cacaca;
width: 100%;
margin: 30px 0;
}
.error-message {
color: red;
font-weight: bold;
padding: 20px;
text-align: center;
}
@media (max-width: 768px) {
.history-wrap .row {
flex-direction: column;
}
.history-wrap .col-lg-1,
.history-wrap .col-lg-10 {
flex: 1 1 100%;
padding-left: 0;
}
.history-wrap .title_h3 {
text-align: left;
margin-bottom: 10px;
}
}
</style>
<div id="bo_list" style="width:<?php echo $width; ?>;">
<?php if ($is_category) { ?>
<nav id="bo_cate">
<h2><?php echo $board['bo_subject']; ?> 카테고리</h2>
<ul id="bo_cate_ul">
<?php echo $category_option; ?>
</ul>
</nav>
<?php } ?>
<form name="fboardlist" id="fboardlist" action="<?php echo G5_BBS_URL; ?>/board_list_update.php" method="post">
<input type="hidden" name="bo_table" value="<?php echo $bo_table; ?>">
<input type="hidden" name="sfl" value="<?php echo $sfl; ?>">
<input type="hidden" name="stx" value="<?php echo $stx; ?>">
<input type="hidden" name="spt" value="<?php echo $spt; ?>">
<input type="hidden" name="sca" value="<?php echo $sca; ?>">
<input type="hidden" name="sst" value="<?php echo $sst; ?>">
<input type="hidden" name="sod" value="<?php echo $sod; ?>">
<input type="hidden" name="page" value="<?php echo $page; ?>">
<input type="hidden" name="sw" value="">
<div id="bo_btn_top">
<div id="bo_list_total">
<span>Total <?php echo number_format($total_count); ?>건</span>
<?php echo $page; ?> 페이지
</div>
<?php if ($write_href) { ?>
<ul class="btn_bo_user">
<li><a href="<?php echo $write_href; ?>" class="btn_b01 btn">글쓰기</a></li>
</ul>
<?php } ?>
</div>
<div class="tbl_head01 tbl_wrap">
<div class="history-wrap">
<?php if (empty($history_data)) { ?>
<div style="text-align:center; padding:50px; color:#999;">
등록된 연혁이 없습니다.
</div>
<?php } else { ?>
<?php foreach ($history_data as $year => $items) { ?>
<h2 class="title_h2"><?php echo htmlspecialchars($year); ?>년</h2>
<div class="container">
<?php foreach ($items as $item) { ?>
<div class="row">
<div class="col-lg-1"></div>
<div class="col-lg-1 title_h3">
<?php echo htmlspecialchars($item['month']); ?>월
</div>
<div class="col-lg-10">
<div class="history-item">
<?php echo format_history_content($item['content']); ?>
<div style="clear:both;"></div>
</div>
</div>
</div>
<?php } ?>
</div>
<div class="divider"></div>
<?php } ?>
<?php } ?>
</div>
</div>
<?php if (isset($write_pages)) echo $write_pages; ?>
</form>
<!-- 검색 폼 -->
<?php if ($is_search) { ?>
<div class="bo_sch_wrap">
<fieldset class="bo_sch">
<h3>검색</h3>
<form name="fsearch" method="get">
<input type="hidden" name="bo_table" value="<?php echo $bo_table; ?>">
<input type="hidden" name="sca" value="<?php echo $sca; ?>">
<input type="hidden" name="sop" value="and">
<select name="sfl">
<option value="wr_content"<?php echo ($sfl=='wr_content')?' selected':''; ?>>내용</option>
<option value="ca_name"<?php echo ($sfl=='ca_name')?' selected':''; ?>>연도</option>
<option value="wr_1"<?php echo ($sfl=='wr_1')?' selected':''; ?>>월</option>
</select>
<input type="text" name="stx" value="<?php echo htmlspecialchars(stripslashes($stx)); ?>" placeholder="검색어를 입력해주세요">
<button type="submit" class="sch_btn">검색</button>
</form>
</fieldset>
</div>
<?php } ?>
</div>
<script>
// 기본적인 자바스크립트만 포함
jQuery(function($){
// 검색 토글 기능이 있다면
$(".btn_bo_sch").click(function(){
$(".bo_sch_wrap").toggle();
});
});
</script>