最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

custom field - Vimeo thumbnails

programmeradmin1浏览0评论

I use Advanced Custom Fields to show Vimeo videoes on a site I am creating for a client - The client pastes the vimeo ID (the last letters in the url) in a field, and the video is shown. But I would also like to show thumbnail of the video, I am using the following (not working code) for this:

<?php
$imgid = the_field('video_link');
$hash = unserialize(file_get_contents("/$imgid.php"));
echo $hash[0]['thumbnail_medium'];  
?>

This code only shows the video-ID on the page. But if I, instead for "the_field('video_link')" writes the video-ID in the code - the thumbnail URL is displayed. Does anyone know what I am doing wrong? :)

I use Advanced Custom Fields to show Vimeo videoes on a site I am creating for a client - The client pastes the vimeo ID (the last letters in the url) in a field, and the video is shown. But I would also like to show thumbnail of the video, I am using the following (not working code) for this:

<?php
$imgid = the_field('video_link');
$hash = unserialize(file_get_contents("http://vimeo/api/v2/video/$imgid.php"));
echo $hash[0]['thumbnail_medium'];  
?>

This code only shows the video-ID on the page. But if I, instead for "the_field('video_link')" writes the video-ID in the code - the thumbnail URL is displayed. Does anyone know what I am doing wrong? :)

Share Improve this question edited Aug 8, 2012 at 10:33 pcarvalho 9497 silver badges12 bronze badges asked Aug 7, 2012 at 22:37 CodyCody 2791 gold badge7 silver badges17 bronze badges 4
  • This doesn't really have anything to do with WordPress. Migrating to Stack Overflow where it will be more on-topic. – EAMann Commented Aug 7, 2012 at 23:13
  • @EAMann I just flagged it to port it back to WPSE. This is about the WP Http API and belongs to us. – kaiser Commented Aug 8, 2012 at 1:07
  • 3 file_get_contents() is a vanilla PHP function ... this is using a regular document from a third-party API. The question has absolutely nothing to do with WordPress or the WP_Http API. – EAMann Commented Aug 8, 2012 at 2:39
  • Dupe that was closed: wordpress.stackexchange/questions/61163/vimeo-thumbnails – markratledge Commented Aug 8, 2012 at 4:08
Add a comment  | 

3 Answers 3

Reset to default 3

Maybe this can help

$videoID = the_field('video_link');
$jsonurl = 'http://vimeo/api/v2/video/'.$videoID.'.json';
$json = file_get_contents($jsonurl,0,null,null);
$json_output = json_decode($json,true);
echo '<img src="'. $json_output[0]['thumbnail_large'] .'" />';

It's the same call using json method

//vimeo thumb generator PHP
function getVimeoImg($id, $size = 'thumbnail_large'){
   if(get_transient('vimeo_' . $size . '_' . $id)){
      $thumb_image = get_transient('vimeo_' . $size . '_' . $id);
   }else{
      $json = json_decode( file_get_contents( "http://vimeo/api/v2/video/" . $id . ".json" ) );
      $thumb_image = $json[0]->$size;
      set_transient('vimeo_' . $size . '_' . $id, $thumb_image, 2629743);
  }
  return $thumb_image;
}

add this to functions.php

than call thumbnail echo getVimeoImg('videoID');

If you want to get the Vimeo thumbnail via ID I setup a small application that let’s you do it like so:

https://vimg.now.sh/358629078.jpg

与本文相关的文章

发布评论

评论列表(0)

  1. 暂无评论