XE(Rhymix)/변수 응용

게시물 목록 첫 게시물에게만 썸네일 출력하기

TheStorybook 2022. 5. 12. 20:10

 

 

사이트를 구경하다가 특이한 기능이 있는걸 발견해서요

 

https://dev.to

 

개발자 전문 커뮤니티인데

 

저기는 최근 게시물 1개에 대해서만 목록에 썸네일을 출력해주던데

라이믹스 게시판 목록에서도 최근 게시물 1개에 대해서만 목록에 썸네일을 저렇게 출력이 가능한가해서요!

 

어떤식으로 목록 파일에 입력해야 저런식으로 1개만 출력이 가능할까요?

 

이전 게시물에 이런 글이 없는것 같아 문의드려봐요!

 

 


 

일단 해당 조건문은 게시판 목록이 loop 돌아가는 안쪽에 들어가야 해요.

대강 이런 식의 구조가 될 겁니다.

<li loop="$document_list=>$no,$document">
<!--@if(($total_count - $no) % $module_info->list_count === 0 && $list_config['thumbnail'] && $document->thumbnailExists())-->
<img src="{$document->getThumbnail()}" />
<!--@end-->

블라블라~~ 기타 문서 정보들
</li>

 

안되는 경우 추가 소스들

 

DivisionByZeroError 면, 조건문에서 분자가 0이 되면 안 된다는 뜻인가봐요.
이렇게 해보시죠.


<!--@if($total_count - $no > 0 && ($total_count - $no) % $module_info->list_count === 0 && $list_config['thumbnail'] && $document->thumbnailExists())-->

그리고 람보님 소스가 가장 깔끔한데

 

 


<!--@foreach($documents as $no => $document)-->
<!--@if($document->getThumbnail())-->
{
$firstTh = $document->getThumbnail;
break;
}
<!--@end-->
<!--@end-->


<!--@foreach($documents as $no => $document)-->
<!--@if($document->getThumbnail())-->
{@
$firstTh = $document->getThumbnail();
break;
}
<!--@end-->
<!--@end-->


변수를 정의하는 소스는 반복문 이전에, 예컨대 파일 맨 앞 같은 위치에 두고,

<!--@if($firstTh)-->
이미지 출력
<!--@end-->

 


<!--@foreach($documents as $no => $document)-->
<!--@if($document->getThumbnail())-->
{@
$firstTh = $document->getThumbnail($module_info->card_thumb_width, 'auto', 'ratio');
break;
}
<!--@end-->
<!--@end-->
이렇게 미리 썸네일의 크기도 잡아주는게 필요하겠지요.

그래서

<!--@if($firstTh)-->
<img src="{$firstTh}"/>
<!--@end-->