Skip to content

Instantly share code, notes, and snippets.

@tjhole
Created December 5, 2013 13:07
Show Gist options
  • Save tjhole/7804868 to your computer and use it in GitHub Desktop.
Save tjhole/7804868 to your computer and use it in GitHub Desktop.
WORDPRESS: Get And Cache Vimeo Thumbnails
// Get And Cache Vimeo Thumbnails
function get_vimeo_thumb($id, $size = 'thumbnail_small')
{
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;
}
// Simple Usage
<?php
echo '<img src="' . get_vimeo_thumb(43096888) . '">';
echo '<img src="' . get_vimeo_thumb(43096888, 'thumbnail_medium') . '">';
echo '<img src="' . get_vimeo_thumb(43096888, 'thumbnail_large') . '">';
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment