썸네일(thumbnail) 이미지 URL 출력

썸네일 이미지 url은 아래 코드를 사용하면 썸네일에 관한 모든 정보가 나온다.

<?php echo get_the_post_thumbnail($post->ID,'thumbnail', $single=true) ?>

위 코드를 작성하면 출력은 아래와 같이 나오게 된다.

<img width="150" height="150" src="http://werty.co.kr/Blog/wp-content/uploads/2012/04/이미지.jpg" alt="SONY DSC" title="SONY DSC" 0="" />

하지만 실제로 딱 썸네일 이미지 url만 필요할 때가 있다.

아래 코드가 바로 실제 썸네일 이미지 url만 가져오는 정보다.

<?php echo get_the_post_thumbnail_src(get_the_post_thumbnail($post->ID,'thumbnail', $single=true)) ?>

 이 코드가 제대로 발동하기 위해선 functions.php를 수정해줘야한다.

themes/테마/functions.php에 아래 코드를 추가한다.

function get_the_post_thumbnail_src($img)
{
return (preg_match('~\bsrc="([^"]++)"~', $img, $matches)) ? $matches[1] : '';
}

 

Subscribe
Notify of
guest

이 사이트는 스팸을 줄이는 아키스밋을 사용합니다. 댓글이 어떻게 처리되는지 알아보십시오.

1 댓글
Oldest
Newest
Inline Feedbacks
View all comments
유승우
유승우
8 years ago

하루종일 찾아헤멘 꼭 필요하던 자료인데, 감사합니다!

TOP