blog.knym.net | I'm searching something to change my life.

wordpressで記事のサムネイルを表示

php; first-line: 0;">wp_get_attachment_metadata( $id ) 
をつかって、サムネイルを探すよりは、下記の方法のようにphpThumb()を使ってサムネイルを生成した方が楽だという結論に至った。


WordPress ポストのサムネイルは phpThumb() で – tanigami.jp


phpThumb()はwatermarkも入れられる多機能っぷりに感動。


vimeoのサムネイル画像の取り方は下記を参照


WordPress › Support » [Plugin: Viper's Video Quicktags] Automatic Vimeo thumbnail


</p>

<p>function the_image($type='thumbnail',$num=0){
    require_once("HTTP/Request.php");
    global $post;
    if(hasPostMeta("main image")){
        $html = get_post_meta($post->ID,"main image", true);
    }else{
        $html = $post->post_content;
    }
    preg_match_all('/&lt;img.+src=<a href="[^\'&quot;]+">\'"</a>[\'"].*>/i', $html, $imgmatch);
    preg_match_all('/vimeo&#46;com\/([^\'"]+)&#91;\/vimeo&#93;/i', $html, $vimeomatch);
    $imgsrc ='';
    if(count($imgmatch[1])>0){
        $src = $imgmatch[1][0];
        $hr = new HTTP_Request($src);
        $hr->setMethod(HTTP_REQUEST_METHOD_HEAD);
        $hr->sendRequest();
        $code = $hr->getResponseCode();
        if($code == 200){
            $imgsrc = $src;
        }
    }else if(count($vimeomatch[1])>0){
        $imgid = $vimeomatch[1][0];//4715514;
            $hash = unserialize(file_get_contents("http://vimeo.com/api/v2/video/$imgid.php"));
            foreach($hash as $hashed){
                $imgsrc=  $hashed[thumbnail_medium];
            }
    }
    if ($imgsrc){
        if($type=='thumbnail'){
            echo '<img src="/shared/php/phpThumb/phpThumb.php?src='.$imgsrc.'&wl=60&hl=60&zc=1&q=80" />';
        }else if($type=='medium'){
            echo '<img src="/shared/php/phpThumb/phpThumb.php?src='.$imgsrc.'&wl=140&hl=90&zc=1&q=80" />';</p>

<pre><code>    }
}else{

}
</code></pre>

<p>}

Related Posts

Write a Comment

XHTML: You can use these tags: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>

 

Essentials

Meta

Pages

Categories