Vimeo thumbnails

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.com/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? :)

Topic vimeo advanced-custom-fields custom-field Wordpress

Category Web


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

//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.com/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');


Maybe this can help

$videoID = the_field('video_link');
$jsonurl = 'http://vimeo.com/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

About

Geeks Mental is a community that publishes articles and tutorials about Web, Android, Data Science, new techniques and Linux security.