최신게시글에서 더보기 버튼 클릭하면 앞에 출력된 게시글이 또 나옵니다
관련링크
본문
최신게시글을 랜덤 출력되게 되있던 것을
최신글 출력으로 수정했는데, 더보기 버튼을 클릭하면
앞쪽에 출력된 게시글이 뒤에 또 나오네요.
어디를 어떻게 수정해야 할까요?
최신글을 1234 페이지 형식으로 보여주지 않고,
하단에 '더보기' 버튼을 누르면 이어서 불러오게 되어있습니다.
3개 파일 첨부합니다. 고수님들 한번 보아주세요ㅠ
index.php
latest.lib.php
latest.skin.php
index.php
<div class="latest_wr">
<!-- 사진 최신글2(갤러리) { -->
<?php
// 이 함수가 바로 최신글을 추출하는 역할을 합니다.
// 사용방법 : latest(스킨, 게시판아이디, 출력라인, 글자수);
// 테마의 스킨을 사용하려면 theme/basic 과 같이 지정
$latest_option = array("sca" => $sca,"page" => 1);
echo latest_all("pic_block", "a_chazeeun,a_hansanghee,a_hwanghyera,a_hwanginh,a_juhoyoungo,a_junghyelynn,a_jungkiyoung,a_kimeunsu,a_kimheekyoung,a_kimilyoung,a_kimjeongtae,a_kimseoin,a_kimtaeseon,a_leesangkuk,a_ohjihoon,a_parksunyoung,a_shinwoigeun,a_songhahoon,a_songyumi,a_sonhokwang,a_sonjoonsung,a_yangyoungmo,a_yoongwangseok", 42, 15,1,$latest_option); //여러게시판에서 글 불러오기
?>
<!-- } 사진 최신글2 끝 -->
</div>
latest.lib.php
// 페이징 추가
if($options['page']) {
$page = $options['page'];
$from_record = ($page - 1) * $rows; // 시작 열을 구함
if($page == 1) {
$sql_common = " from {$g5['board_new_table']} a where find_in_set(a.bo_table, '{$bo_tables}')";
$sql_common .= " and a.wr_id = a.wr_parent {$sql_search} ";
$sql = " select count(*) as cnt {$sql_common} {$sql_order}";
$row = sql_fetch($sql);
$total_count = $row['cnt'];
$total_page = ceil($total_count / $rows); // 전체 페이지 계산
}
}else{
$page = 1;
$from_record = 0;
$total_page = 1;
}
$list = array();
$sql_common = " from {$g5['board_new_table']} a where find_in_set(a.bo_table, '{$bo_tables}')";
$sql_common .= " and a.wr_id = a.wr_parent {$sql_search} ";
$sql_order = " order by a.bn_id desc ";
$sql = " select a.* {$sql_common} {$sql_order} limit {$from_record}, {$rows}";
$result = sql_query($sql);
for ($i=0; $row=sql_fetch_array($result); $i++) {
$sql = " select * from {$g5['board_table']} where bo_table = '{$row['bo_table']}' ";
$board = sql_fetch($sql);
$tmp_write_table = $g5['write_prefix'] . $row['bo_table'];
$row2 = sql_fetch(" select * from {$tmp_write_table} where wr_id = '{$row['wr_id']}' ");
$list[$i] = $row2;
$list[$i] = get_list($row2, $board, $latest_skin_url, $subject_len);
$list[$i]['bo_subject'] = $row['bo_subject'];
$list[$i]['bo_table'] = $row['bo_table'];
}
ob_start();
if($page == 1) {
include $latest_skin_path.'/latest.skin.php';
}else{
include $latest_skin_path.'/latest2.skin.php';
}
$content = ob_get_contents();
ob_end_clean();
return $content;
}
?>
latest.skin.php
<?php
if (!defined('_GNUBOARD_')) exit; // 개별 페이지 접근 불가
include_once(G5_LIB_PATH.'/thumbnail.lib.php');
// add_stylesheet('css 구문', 출력순서); 숫자가 작을 수록 먼저 출력됨
add_stylesheet('<link rel="stylesheet" href="'.$latest_skin_url.'/style.css">', 0);
$thumb_width = 260;
$thumb_height = 150;
$list_count = (is_array($list) && $list) ? count($list) : 0;
//shuffle($list); // 출력 랜덤
?>
<div class="pic_lt">
<ul class="pic_ul">
<?php
for ($i=0; $i<$list_count; $i++) {
$thumb = get_list_thumbnail($list[$i]['bo_table'], $list[$i]['wr_id'], $thumb_width, $thumb_height, false, true);
if($thumb['src']) {
$img = $thumb['src'];
} else {
$img = G5_IMG_URL.'/no_img.png';
$thumb['alt'] = '이미지가 없습니다.';
}
$img_content = '<img src="'.$img.'" alt="'.$thumb['alt'].'" >';
$wr_href = get_pretty_url($list[$i]['bo_table'], $list[$i]['wr_id']);
?>
<li class="gallery_li">
<a href="<?php echo $wr_href; ?>" class="lt_img"><?php echo run_replace('thumb_image_tag', $img_content, $thumb); ?></a>
<?php
if ($list[$i]['icon_secret']) echo "<i class=\"fa fa-lock\" aria-hidden=\"true\"></i><span class=\"sound_only\">비밀글</span> ";
echo "<a href=\"".$wr_href."\"> ";
if ($list[$i]['is_notice'])
echo "<strong>".$list[$i]['subject']."</strong>";
else
echo $list[$i]['subject'];
echo "</a>";
if ($list[$i]['icon_new']) echo "<span class=\"new_icon\">N<span class=\"sound_only\">새글</span></span>";
if ($list[$i]['icon_hot']) echo "<span class=\"hot_icon\">H<span class=\"sound_only\">인기글</span></span>";
// if ($list[$i]['link']['count']) { echo "[{$list[$i]['link']['count']}]"; }
// if ($list[$i]['file']['count']) { echo "<{$list[$i]['file']['count']}>"; }
// echo $list[$i]['icon_reply']." ";
// if ($list[$i]['icon_file']) echo " <i class=\"fa fa-download\" aria-hidden=\"true\"></i>" ;
// if ($list[$i]['icon_link']) echo " <i class=\"fa fa-link\" aria-hidden=\"true\"></i>" ;
if ($list[$i]['comment_cnt']) echo "
<span class=\"lt_cmt\">".$list[$i]['wr_comment']."</span>";
?>
<?php } ?>
<?php if ($list_count == 0) { //게시물이 없을 때 ?>
<li class="empty_li">게시물이 없습니다.</li>
<?php } ?>
</ul>
</div>
<?php if ( $total_page > 1 ) { ?>
<div class="bo_cate_box"><div class="bo_cate_more la_page" style="display:inline-block;margin:0"><a href="javascript:fnc_add()">포트폴리오 더보기</a></div></div>
<script>
var total_page = <?php echo $total_page;?>;
var page = 1;
function fnc_add(){
npage = page + 1;
$.ajax({
type : 'POST',
url : "/ajax/la_more.php",
data : {page:npage,sca:g5_sca,skin:"pic_block"},
dataType: "html",
async: false,
cache: false,
error : function(error) {
alert("Error!");
},
success : function(data) {
$(".pic_ul").append(data);
page = npage;
if (page == total_page){
$(".la_page").hide();
}
},
complete : function() {
//alert("complete!");
}
});
}
</script>
<?php } ?>
답변 2
더보기 버튼이 la_more.php 여기로 전달하는데
page, sca, skin 요렇게 3개 값을 던지긴 하는데....
아무것도 반영하지 않는 느낌이네요
url : "/ajax/la_more.php",
data : {page:npage,sca:g5_sca,skin:"pic_block"},
la_more.php 에, page, sca, skin 파라미터를 전달한다는 의미입니다.
la_more.php 에서
파라미터 값 전달은 잘 받았는지..
DB 조회는 잘 되었는지..
더 보기 게시글 데이터는 잘 리턴하였는지..
echo $page; echo $sql; (sql문) 식으로 디버깅 해 볼 수 있습니다.
ajax 파일 디버깅하는 방법입니다. https://marscompany.tistory.com/7