Settings'; array_unshift($links, $settings_link); } return $links; } function register_vid_settings() { // whitelist options register_setting( 'vid_options', 'vid_options_field' ); } //------------------------------------------------------------------------------------------------------------------------------- /** * Admin page plugin options ** //---------------------------------------------------------------------------------------------------------------------------- */ function vid_plugin_options() { ?>
Why not donate?
Each video is added as custom meta fields which means you can call auto-generated thumbnails from both YouTube and Vimeo to be used instead of a post thumbnail.
To do this:
Open archive.php and find where your post thumbnail sits within the loop. Replace it with the code below.
This code finds the meta information for each post, checks to see if a YouTube video is present. If it isn't, checks for a Vimeo video. If neither have been used, and assuming you are using the "Featured Image" for your thumbnail, it will fall back to the Featured Image. If that hasn't been set either, no image will display.
global $post;
$meta = get_post_meta($post->ID,'_video_meta',TRUE);
/* Setup $post and get the meta data from the custom fields */
if ( $meta['type'] == "youtube" ) {
/* Break the video URL apart to find the ID */
$loc = strpos($meta['url'],"v=");
$videoid = substr($meta['url'], $loc + 2);
/* YouTube give you a choice of 3 thumbnails: 0.jpg, 1.jpg, 2.jpg */
echo '‹img src="http://img.youtube.com/vi/'.$videoid.'/0.jpg" alt="the_title();>" /›';
} else if ( $meta['type'] == "vimeo" ) {
/* Vimeo's URL structure is slightly different and needs breaking apart differently */
$loc = explode( "/", $meta['url'] );
$videoid = end($loc);
/* Vimeo stores all info about each video in JSON, PHP and XML Formats. This is the PHP version */
$hash = unserialize(file_get_contents("http://vimeo.com/api/v2/video/$videoid.php"));
/* Depending on the size of the image needed you could use ['thumbnail_large'], ['thumbnail_medium'] or ['thumbnail_small'] */
echo '‹img src="'.$hash[0]['thumbnail_large'].'" alt="the_title();" /›';
} else {
the_post_thumbnail( 'thumbnail' );
}
The autogenerated images will need some styling to make them display the same way your post thumbnails do. This can be done with standard CSS though, exactly as you would do with any other images.
Happy coding! ~ grin!
Check out the documentation.
"; $text .= "Documentation'.$vid_desc.'
'; // Else this is a Vimeo video as there are only two options } else { // Find the Vimeo ID $loc = explode( "/", $meta['url'] ); $videoid = end($loc); extract(shortcode_atts(array( "vid_url" => $videoid, "vid_name" => $meta['name'], "vid_desc" => $meta['description'], ), $atts)); return ''.$vid_desc.'
'; } } add_shortcode('responsive_vid', 'videoCode'); ?>