Extra Form
PHP PHP 7.4
CMS Rhymix 2.x

리스트 글제목 아래에 댓글을 함께 출력하는기능을 SketchBook5 게시판스킨에 적용을 해 보았습니다.

[Sample] https://moonhouse.co.kr/qa

 

2021-09-03 at 08.20.05.jpg

 

<!-- 코멘트 리스트 시작 -->
{@$i = 0}
<tr class="r" loop="$document->getComments() => $key,$val" cond="$i < 2">
{@$i++}

    <td class="replyContent" >
        <div <!--@if($val->depth < 11)-->style="margin-left:{($val->depth)*1.3}em"<!--@else-->style="margin-left:13em"<!--@end--> class="replyIndent">
            <div <!--@if($mi->div_column == 'yescolumn')-->style="width:100%"<!--@end--> style="text-align:left">
                <a href="{getUrl('document_srl',$document->document_srl, 'comment_srl', $val->comment_srl)}#comment_{$val->comment_srl}" title="">
                    {cut_str(strip_tags($val->content),60,'...')}
                </a>
            </div>
        </div>
    </td>
    <td class="author">{($val->nick_name)}</td>
    <td class="date">{zdate($val->regdate, 'm.d/H.i')}</td>

</tr>
<!--@end-->
<!-- 코멘트 리스트 끝 -->

 

빨간색코드로 댓글의 수를 조절할 수 는 있겠는데

댓글영역의 상단에 최근댓글순으로 올릴 수는 없을까요?

아님 댓글 영역을 높이조절을 하여 스크롤로 보이게 할 수는 없을까요?

<tr>영역을 아무리 감싸도 높이 조절이 안되네요.

 

적용된 SketchBook5 게시판스킨 - 아직 갯수조절 코드는 삽입되어져 있지 않습니다. 

https://moonhouse.co.kr/xemy/530374 

  • profile

    $document->getComments()
    이것도 배열일테니
    이걸 다른 변수에 담아서 그 변수의 배열을 뒤집으면 되지 않을까요?

    {@$i = 0}
    {@$comments_list = $document->getComments();}
    {@$comments_list = array_reverse($comments_list );}
    <tr class="r" loop="$comments_list => $key,$val" cond="$i < 2">

  • profile ?
    오! Good~
    잘 작동하네요.
    역시 고수님들에게 물어 봐야되...
    감사합니다.
  • ? profile
    아래 추가 댓글을 달았지만 댓글이 페이지를 넘어가는 경우도 확인을 해보셔야 할것입니다.
  • profile profile
    굳이 여러줄을 쓰지 않고도
    {@$i = 0}
    <tr class="r" loop="array_reverse($document->getComments()) => $key,$val" cond="$i < 2">

    이런식으로도 충분히 가능합니다.
    신문법이 작동이 안된다면 <!--@foreach()--> 문으로 바꿔주시면 되고요.
  • profile
    다만 걱정되는 것은 코멘트가 페이지가 적용될텐데 다른 것이 없으면 첫페이지에 해당하는 것만 결과로 가져올수 있다는 것입니다.
    그렇다면 페이지수를 계산해서 마지막 페이지의 것을 가져오게 해야할꺼에요.
  • profile ?
    아직 까지 댓글이 한페이지를 넘기는 일이 없어서 잘 모르갰지만 연구해 봐야 겠네요.

    근데 혹시 댓글 영역을 높이조절을 하여 스크롤로 보이게 할 수는 없을까요? 를 구현하는 방법은 없을가요?
    아님 토글적용 하는 방법이나...
    너무 무리한 요구이면 죄송합니다.
  • ? profile
    현재 html로 변환되서 브라우저에서 보이는 html구조상으로는 안됩니다.

    tr td안에 코멘트들만 모아서 div로 감싸고 해당 div의 높이를 제한, overflow를 주면 되는데

    지금은 게시물제목이나 각각의 코멘트나 모두 각각 tr이네요.
  • profile
    목록에서 댓글을 가져오는 쿼리를 사용하는 경우 사이트속도가 저하될 수 있습니다.

    추후 사이트가 성장하였을때 해당 기능이 제거되어야할 수 있으니 해당 기능에 큰 미련을 가지지 않는 것이 좋을 것 같고요..

    그리고 getComments 를 뒤집는 것보다 새롭게 디비에서 최신순으로 가져올 수 있도록 쿼리를 하는 것이 좀 더 나은 선택입니다.
  • profile profile
    쿼리문부터 역순으로 정렬해서 가져오는게 낫다는 것은 알지만
    전 코어를 수정하지 않고 그걸 만들만한 능력은 없어서요 -0-;;;;;
  • profile profile

    commentModel 클래스 안에 getNewestCommentList 함수를 사용하면 아래 쿼리를 이용합니다.

    <query id="getNewestCommentList" action="select">
    <tables>
    <table name="comments" />
    </tables>
    <columns>
    <column name="*" />
    </columns>
    <conditions>
    <condition operation="equal" column="status" var="status" pipe="and" />
    <condition operation="equal" column="is_secret" var="is_secret" pipe="and" />
    <condition operation="in" column="module_srl" var="module_srl" filter="number" pipe="and" />
    <condition operation="equal" column="document_srl" var="document_srl" filter="number" pipe="and" />
    </conditions>
    <navigation>
    <index var="sort_index" default="list_order" order="asc" />
    <list_count var="list_count" default="20" />
    </navigation>
    </query>


    굳이 코어를 수정하지 않고 module_srl이랑 같이 잘 넘기시면 됩니다.

     

    $args = new stdClass();

    $args->list_count = 5;

    $args->module_srl = $module_srl

    //문서번호는 상황에 맞게 코드 알아서 적절히

    $args->document_srl = $document_srl; 

    $comment_list = getModel('comment')->getNewestCommentList($args);

  • profile profile
    오!!! getNewestCommentList 가 있군요!!!!!
    관련 소스코드를 보기는 했는데 getCommentList만 보고 정렬순서는 고정이군!
    하고 역순으로 동작하게 코어를 수정할수는 없으니 그건 포기하자!
    라고 생각했는데... 이미 만들어져 있군요.ㅋ