댓글노출 최신글을수정하려고 합니다.

댓글노출 최신글을수정하려고 합니다.

QA

댓글노출 최신글을수정하려고 합니다.

본문

* 1번 게시물 글
* 2번 게시물 글 [1]
   ㄴ 등록된 댓글...
* 3번 게시물 글 
* 4번 게시물 글 [3]
* 5번 게시물 글 [1]

예를 들어서 위 처럼 최신글이 5개 노출되고 댓글들이 달렸을경우 
맨 상단의 글에 등록된 댓글만 노출이 되게 하고 싶습니다.
그러니까 댓글내용은 맨 위의댓글 단 하나만 보여지게 하려고 합니다.


----------------------------------------------- latest.skin.php 소스 입니다.


<?
if (!defined("_GNUBOARD_")) exit; // 개별 페이지 접근 불가 
?>
<style type='text/css'>
ul#comm {margin:0;padding:0;}
ul#comm li {list-style-type:none;margin:0;padding:5px;font-size:12px;}
</style>

	<ul id='comm'>
<?
$cnt = count($list);
for ($i=0; $i<$cnt; $i++) {
			
			echo "<li>";
            echo "<a href='".$list[$i]['href']."&sca=".urlencode($list[$i]['ca_name'])."'>";
			//echo "<span class='datetime'>[".$list[$i]['datetime2']."]</span> ";
			//echo "<span class='category'>[".$list[$i]['ca_name']."]</span> ";
			//echo "<b>".$list[$i]['wr_name']."</b> | " ;
			//echo "<img src='$g4[path]/img/jisik_q.gif' width='{$img_width}' height='{$img_height}'  border='0'>";

			echo "<font style='font-family:나눔고딕 ExtraBold; font-size:13pt; color:#DC7D0F;'>Q</font>  ";
            echo "<font style='font-family:돋옴; 'color:#888888;font-size:9px;'>".$list[$i]['subject']."</span> ";
            if ($list[$i]['comment_cnt'])
                echo "<span style='font-family:나눔고딕 Bold;; font-size:10pt; color:#CC6633;'>".$list[$i]['comment_cnt']."</span> ";
            echo " " . $list[$i]['icon_new'];
            echo "</a>";
?>

<?		 ////★★★★여기서부터 최근글에 댓글뽑기 소스★★★★
			//$this_ca_name = $list[$i]['ca_name'];
			$this_wr_parent = $list[$i]['wr_id'];

            if ($list[$i]['comment_cnt']) {
			
			echo "<div style='border:solid #fff 1px;background:#fff;margin:2px;padding:-5px;font-size:12px;'>";

			$write_table = $g4['write_prefix'].$bo_table;
			
			$sql_num = " select count(*) as num from $write_table where wr_parent = '$this_wr_parent' and wr_is_comment = 1 and wr_comment_reply = '' "; 
			$row_num = sql_fetch($sql_num);
			//$comment_num = $row_num['num']; //전체댓글수
			$display_comment_num = 1; //메인에 뽑을 댓글수
			
//댓글 뽑기
			$sql_comment = " select * from $write_table where wr_parent = '$this_wr_parent' and wr_is_comment = 1 and wr_comment_reply = '' order by wr_id desc ";
			$result_comment = sql_query($sql_comment);
				for ($c=0; $row_comment=sql_fetch_array($result_comment); $c++) 
				{
				$this_day = substr($row_comment['wr_datetime'],0,10);
				if ($this_day==$g4['time_ymd']) $datetime2 = substr($row_comment['wr_datetime'],11,5);
				else $datetime2 = substr($row_comment['wr_datetime'],5,5);

				echo "<div style='text-align:left;line-height:1.5;'> <!---((((---->";
				//echo "<span style='color:#666;font-size:12px;'><b>".$row_comment['wr_name']."</b></span> ";
				//echo "<img src='$g4[path]/img/jisik_a.gif' width='{$img_width}' height='{$img_height}'  border='0'>"."<span style='color:#aaaccc;font-size:11px;'>".$datetime2."</span> ";
				echo "<font style='font-family:나눔고딕 ExtraBold; font-size:13pt; color:#799D5D;'> A</font>  ";
				//echo "<span style='color:#777;font-size:12px;'>".$row_comment['wr_content']."</span>";
                  echo mb_strimwidth($row_comment['wr_content'],0,100,"…","utf-8"); //댓글 출력글자수 100자로 
				
//답댓글 입력폼
//				if ($_SESSION['ss_mb_id']==$list[$i]['mb_id']) { ///원글쓴이가 본인일 경우 답글달기 버튼 보임. 적용하지 않으려면 주석처리
				if ($_SESSION['ss_mb_id']) { ///로그인 중일 경우 답글달기 버튼 보임. 적용하지 않으려면 주석처리
				$form_width = "100%"; ///댓글폼의 가로폭
?>

<!--
	<span id='show-re-comment-form<?=$list[$i]['wr_id']?><?=$c?>' style='margin:5px;background:navy;color:#fff;padding:2px;cursor:pointer;font-size:11px;'>답댓글</span>
-->

<!--
	<div id='re-comment-form<?=$list[$i]['wr_id']?><?=$c?>' style='display:none;'>
	<form name="fviewcomment" method="post" action="<?=$g4['bbs_path']?>/comment_latest_update.php" onsubmit="return fviewcomment_submit(this);" autocomplete="off" style="margin:0px;">
	<input type=hidden name=w           id=w value='c'>
	<input type=hidden name=mb_id       value='<?=$member['mb_id']?>'>
	<input type=hidden name=bo_table    value='<?=$bo_table?>'>
	<input type=hidden name=wr_id       value='<?=$this_wr_parent?>'>
	<input type=hidden name=wr_comment  value='<?=$row_comment['wr_comment']?>'>
	<input type=hidden name=wr_comment_reply  value='A'>
	<input type=hidden name=comment_id  id='comment_id' value=''>
	<input type=hidden name=sca         value='<?=$this_ca_name?>'>
	<input type=hidden name=set        value='goto_main'> 
-->

	<!---댓글을 단 후 메인으로 가고자 하면 goto_main, 게시판으로 가고자 하면 goto_board---->
	<!---해당소스는 comment_latest_update.php 339행, 344행 참조---->

<!--
	<textarea id='wr_content' name='wr_content' rows=3 itemname='답글달기' required style='width:<?=$form_width?>;word-break:break-all;font-size:12px;' class=tx></textarea>
	<div style='margin:0;'><input type='submit' value=' 답글달기 ' accesskey='s' style='font-size:12px;'></div>
-->
	</form>
	</div>
<?
				} ///원글쓴이가 본인이거나 혹은 로그인 중일 경우 답글달기 버튼 보임. 적용하지 않으려면 주석처리


///댓글의 답댓글 뽑기

$sql_comment_reply = " select * from $write_table where wr_parent = '$this_wr_parent' and wr_is_comment = 1 and wr_comment = '$row_comment[wr_comment]' and wr_comment_reply != '' order by wr_comment_reply desc ";
$result_comment_reply = sql_query($sql_comment_reply);

for ($d=0; $row_comment_reply=sql_fetch_array($result_comment_reply); $d++) 
{
$this_day_comment_reply = substr($row_comment_reply['wr_datetime'],0,10);
if ($this_day_comment_reply == $g4['time_ymd']) $datetime2_comment_reply = substr($row_comment_reply['wr_datetime'],11,5);
else $datetime2_comment_reply = substr($row_comment_reply['wr_datetime'],5,5);

echo "<div style='border:dotted #ccc 1px;margin:5px 5px 5px 15px;padding:5px;'>";
echo "<span style='color:#666;font-size:12px;'><b>".$row_comment_reply['wr_name']."</b></span> ";
echo "<span style='color:#aaaccc;font-size:11px;'>".$datetime2_comment_reply."</span> ";
echo "<span style='color:#777;font-size:12px;'>".$row_comment_reply['wr_content']."</span>";
echo "</div>";
}

				echo "</div> <!---))))---->";
				
				if ($c == $display_comment_num-1) break; //
				}
				
		if ($comment_num > $display_comment_num) { //전체 댓글수가 메인에 뽑을 댓글수보다 많으면 출력. 게시글로 가는 링크
		echo "<div style='margin-top:5px;text-align:center;'>";
		echo "<a href='".$g4['bbs_path']."/board.php?bo_table=".$bo_table."&sca=".urlencode($this_ca_name)."&wr_id=".$this_wr_parent."'></a>";
		echo "</div>";
		}
				
			echo "</div>";
?>
<script type="text/javascript">
$(document).ready(function(){
	<?
		$sql_comment = " select * from $write_table where wr_parent = '$this_wr_parent' and wr_is_comment = 1 and wr_comment_reply = '' order by wr_id desc ";
		$result_comment = sql_query($sql_comment);
		for ($c=0; $row=sql_fetch_array($result_comment); $c++) 
		{
	?>
	$("span#show-re-comment-form<?=$list[$i]['wr_id']?><?=$c?>").click(function(){
		$("div#re-comment-form<?=$list[$i]['wr_id']?><?=$c?>").toggle("fast");
	});
	<? } ?>
});
</script>
			<?	} ////★★★★여기까지 최근글에 댓글뽑기 소스★★★★ ?>


		</li>

<? } ?>
<? if (count($list) == 0) { ?><li>게시물이 없습니다.</li><? } ?>  
	</ul>

-------------------------------------------------------

이부분에 제어하는 부분이 있으면 어디를 어떻게 고쳐야 하는지 방법좀 알려주세요...

이 질문에 댓글 쓰기 :

답변 2

댓글뽑기부분에 처음과 끝에
 
if ($i == 0) {
 
댓글뽑기내용
 
 
}
 
이렇게하세요.

정말 감사합니다.
여기저기에 옮겨가면서 넣어보니 적용이 되네요.ㅎㅎ
안되는건줄 알았는데 if ($i == 0)를 if ($i == 2)이렇게 하니까 잘 적용이 됬습니다.^^

아.. 근데 저 소스가 댓글 갯수에 영향을 주는거 같네요. 1로 하면 댓글1개짜리 글의 댓글이 노출되고
2로 하면 댓글 2개짜리글의 댓글이 노출되는거 같아요.

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

회원로그인

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