【问题标题】:Featured image from an embedded Vimeo video in wordpresswordpress 中嵌入 Vimeo 视频的特色图片
【发布时间】:2012-09-26 17:39:57
【问题描述】:

我一直在尝试将 this script 改编为 vimeo,但没有结果。我不想使用插件,只是一个脚本来添加仅适用于 Vimeo 和 Youtube 的 functions.php。

我可以通过以下方式获取网址图片:

$hash = unserialize(file_get_contents('http://vimeo.com/api/v2/video/'. $vimeo_id .'.php')); 
echo $hash[0]['thumbnail_large'];}  

但是我不知道怎么取这个在"$vimeo_thumb_url"中介绍一下

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_id, ARRAY_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_str( parse_url( $vimeo_url, PHP_URL_QUERY ) ); 
        $vimeo_id = $v; 
    } // end if 

        return $vimeo_id;  

} // end get_vimeo_id 

【问题讨论】:

    标签: wordpress image vimeo


    【解决方案1】:

    你可以通过这样做获得图片链接:

    $hash = unserialize(file_get_contents("http://vimeo.com/api/v2/video/$video_id.php"));
    $src = $hash[0]['thumbnail_large'];
    

    哈希数组包含不同大小图像的 src。只需选择,您需要什么。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2012-09-03
      • 1970-01-01
      • 1970-01-01
      • 2014-04-04
      • 2014-12-26
      • 2019-04-12
      • 2012-09-05
      • 1970-01-01
      相关资源
      最近更新 更多