채택완료

본문에서 가장 위에 있는 이미지를 출력하고 싶습니다

아래 코드는 최신글에 외부 이미지를 출력하는데

본문에 이미지가 여러개 있으면 그 중에 하나가 랜덤으로 출력되더군요

 

가장 위에 있는 이미지만 출력하게 하려면

코드를 어떻게 수정해야 하나요?

 

Copy
if (!isset($thumb['src']) || empty($thumb['src'])) {
    if ( $matches = get_editor_image($list[$i]['wr_content'], false) ){
        $k = count($matches[1]) - 1 < 1 ? 0 : mt_rand(0, count($matches[1]) - 1);
        if (isset($matches[1][$k])) {
            // NO_IMAGE로 사이즈를 설정할 때
            $img_content = '<span style="display: block; overflow: hidden; background: url('.$matches[1][$k].') center center no-repeat; background-size: cover;"><span style="display: block; visibility: hidden;">'.$img_content.'</span></span>';
            // 썸네일 width/height 비율로 사이즈를 설정할 때
            //$img_content = '<span style="display: block; overflow: hidden; width: 100%; padding-top: '.(round(($thumb_height / $thumb_width) * 100, 2)).'%; background: url('.$matches[1][$k].') center center no-repeat; background-size: cover;"></span>';
        }
    }
}
|

답변 1개 / 댓글 1개

채택된 답변
+20 포인트

Copy
//$k = count($matches[1]) - 1 < 1 ? 0 : mt_rand(0, count($matches[1]) - 1);

$k = 0;

답변에 대한 댓글 1개

잘되네요. 감사합니다

답변을 작성하려면 로그인이 필요합니다.