예를 들면
추천 받은 댓글이 있는 경우 게시물 목록에 [답변] 표시를 하고 싶습니다.
아래 처럼 해도 게시물 목록에서는 에러만 나고 뭘 해도 안되더군요...
<!--@if($comment->get('voted_count')>1)-->
답변
<!--@end-->
예를 들면
추천 받은 댓글이 있는 경우 게시물 목록에 [답변] 표시를 하고 싶습니다.
아래 처럼 해도 게시물 목록에서는 에러만 나고 뭘 해도 안되더군요...
<!--@if($comment->get('voted_count')>1)-->
답변
<!--@end-->
사용 상 문제는 없을 것 같은데.. 직접 테스트 해본 건 아니라서요..
일단 설명을 붙이자면,
$comment는 게시판 list에서 호출할 수 없습니다.
호출하기 위해서는 getComments()로 코멘트 객체를 불러 올 수 있습니다.
getComments 함수는 document 모듈에 document.item.php에 정의되어 있습니다.
// Get a list of comments $oCommentModel = getModel('comment'); $output = $oCommentModel->getCommentList($this->document_srl, $cpage, $is_admin); if(!$output->toBool() || !count($output->data)) return; // Create commentItem object from a comment list // If admin priviledge is granted on parent posts, you can read its child posts. $accessible = array(); $comment_list = array(); foreach($output->data as $key => $val) { $oCommentItem = new commentItem(); $oCommentItem->setAttribute($val); // If permission is granted to the post, you can access it temporarily if($oCommentItem->isGranted()) $accessible[$val->comment_srl] = true; // If the comment is set to private and it belongs child post, it is allowable to read the comment for who has a admin privilege on its parent post if($val->parent_srl>0 && $val->is_secret == 'Y' && !$oCommentItem->isAccessible() && $accessible[$val->parent_srl]===true) { $oCommentItem->setAccessible(); } $comment_list[$val->comment_srl] = $oCommentItem; } // Variable setting to be displayed on the skin Context::set($cpageStr, $output->page_navigation->cur_page); Context::set('cpage', $output->page_navigation->cur_page); if($output->total_page>1) $this->comment_page_navigation = $output->page_navigation;
대략 이부분을 참고하시면 됩니다.
$commentVote = 0 이랑 ++은 안 돌려도 되지 않나싶은데요.
{@$commentList = $document->getComments();}
<!--@foreach($commentList as $comment)-->
<!--@if($comment->get('voted_count') > 0)-->
답변
<!--@end-->
<!--@end-->
... 또는, (저도 잘은 모르겠지만) getComments 함수를 이미 불러들인(?) 게시판 스킨을 사용하시는 경우(저는 스케치북 씁니다)에는
<!--@foreach($document->getComments() as $comment)-->
<!--@if($comment->voted_count > 0)-->
답변
<!--@end-->
<!--@end-->
... 로 해도 될 것 같습니다. {print_r($comment->voted_count)}로 출력해보니까 추천수가 나오더군요.
우오!! 감사합니다. 잘 출력 됩니다!! 다만 댓글 추천이 여러개인경우
답변 답변 답변 이렇게 출력 되는데.. 1번만 출력 될수 없을까요?
글쎄요;;; 거기까지는 저도 잘 모르겠는데요;;;
혹시 명령문을 삽입한 위치 때문에 '답변'이 반복되는 거 아닐까요?
제가 실험해봤을 땐 게시판 리스트 각 "게시물 항목 내"에서 foreach 돌렸을 때 순조롭게 성공했었거든요.
{$comment->voted_count}는 추천수로 잘 나오구요, 추천수가 '2'일 때 <!--@if($comment->voted_count > 0)-->답변<!--@end-->로 했을 때도 '답변'이 한 번만 떠요.
네. 그래도 표기가 되므로 도움이 많이 됩니다. 다시한번 감사 드립니다. 제가 이 질문만 1년넘게 해오고 있는데 처음으로
목록에 댓글 추천이 있는 글이 따로 표기가 되었습니다.
1년이라뇨 ㅠㅠ 왠지 그 심정 이해가 됩니다;;;
이렇게 한 번 해보시는 건 어떨지요. 저는 되는 것 같기도 한데... socialskyo님 경우을 제대로 재연한 것일지는 확신이 잘 없습니다만..
<!--@foreach($document->getComments() as $comment)--><!--@if($comment->voted_count)-->답변<!--@end-->{@break}<!--@end-->
{@break} 대신 <!--@break-->도 좋구요.
{@
$commentList = $document->getComments();
$commentVote = 0;
}
<!--@foreach($commentList as $comment)-->
{@
if($comment->get('voted_count') > 0) $commentVote++;
}
<!--@end-->
<!--@if($commentVote > 0 )-->
답변
<!--@end-->