Ver Mensaje Individual
  #1 (permalink)  
Antiguo 21/09/2012, 03:07
blanche
 
Fecha de Ingreso: septiembre-2012
Mensajes: 1
Antigüedad: 11 años, 6 meses
Puntos: 0
Thumbnails automáticos en wordpress

Adaptando para vimeo [URL="http://wordpress.stackexchange.com/questions/25808/setting-a-posts-featured-image-from-an-embedded-youtube-video"]un código buenísimo[/URL] para insertar automáticamente los thumbnails de youtube al final me he dado por vencida. Llevo varios dias investigando por internet pero las soluciones no son automaticas como la que he utilizado de youtube.

Seguro que es facilísimo

Sé como obtener la url del thumbnail de vimeo:

Código PHP:
$hash unserialize(file_get_contents('http://vimeo.com/api/v2/video/'$vimeo_id .'.php'));
echo 
$hash[0]['thumbnail_large'];} 
Pero no sé como implementarlo en el código para que "vimeo_thumb_url" utilice la esa url del thumbnail de vimeo. A ver si alguien tiene alguna sugerencia.

Código PHP:

function set_vimeo_as_featured_image($post_id) {  

    
// only want to do this if the post has no thumbnail
    
if(!has_post_thumbnail($post_id)) { 

        
// find the vimeo url
        
$post_array get_post($post_idARRAY_A);
        
$content $post_array['post_content'];
        
$vimeo_id get_vimeo_id($content);

        
// build the thumbnail strings

        
$vimeo_thumb_url '';

        
// next, download the URL of the vimeo image
        
media_sideload_image($vimeo_thumb_url$post_id'Sample vimeo image.');

        
// find the most recent attachment for the given post
        
$attachments get_posts(
            array(
                
'post_type' => 'attachment',
                
'numberposts' => 1,
                
'order' => 'ASC',
                
'post_parent' => $post_id
            
)
        );
        
$attachment $attachments[0];

        
// and set it as the post thumbnail
        
set_post_thumbnail$post_id$attachment->ID );

    } 
// end if

// set_vimeo_as_featured_image
add_action('save_post''set_vimeo_as_featured_image');

function 
get_vimeo_id($content) {

    
// find the vimeo-based URL in the post
    
$urls = array();
    
preg_match('#http://(?:\w+.)?vimeo.com/(?:video/|moogaloop\.swf\?clip_id=)(\w+)#i'$content$urls);
    
// next, locate the vimeo video id
    
$vimeo_id '';
    if(
strlen(trim($vimeo_url)) > 0) {
        
parse_strparse_url$vimeo_urlPHP_URL_QUERY ) );
        
$vimeo_id $v;
    } 
// end if

        
return $vimeo_id

// end get_vimeo_id

////////////////////////////////////////////fin vimeo 
No quiero utilizar pluguins para no acabar teniendo mil pluguins que ralenticen mi web con código innecesario.

Un saludo.