Created
December 5, 2013 13:07
-
-
Save tjhole/7804868 to your computer and use it in GitHub Desktop.
WORDPRESS: Get And Cache Vimeo Thumbnails
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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