2016-11-07 81 views
3

我找到了一個名爲oEmbed Featured Image的插件,它除了輸出最大尺寸外,完全可以做到我想要的任何東西。oEmbed精選圖片(大縮略圖)

插件的默認YouTube輸出大小爲480x360。我需要能夠使用至少YouTube/Vimeo的全分辨率大小。

我想我可以編輯插件中第68行開始的函數。

這裏是我想出來的:

public function oembed_dataparse($return, $data, $url) 
{ 

    if ($yt = $data->provider_name == 'YouTube') 
    { 
     if(preg_match("/^(?:http(?:s)?:\/\/)?(?:www\.)?(?:m\.)?(?:youtu\.be\/|youtube\.com\/(?:(?:watch)?\?(?:.*&)?v(?:i)?=|(?:embed|v|vi|user)\/))([^\?&\"'>]+)/", $data->thumbnail_url, $youtube_id)) 
     $ytvideo_id = $youtube_id; 
     $max = get_headers($data->thumbnail_url); 

     if (substr($max[0], 9, 3) !== '404') 
     { 
      $data->thumbnail_url = 'http://img.youtube.com/vi/$ytvideo_id/maxresdefault.jpg'; 
     } 
    } 

    if ($vm = $data->provider_name == 'Vimeo') 
    { 
     if (preg_match("/https?:\/\/(?:www\.)?vimeo.com\/(?:channels\/(?:\w+\/)?|groups\/([^\/]*)\/videos\/|album\/(\d+)\/video\/|)(\d+)(?:$|\/|\?)/", $data->thumbnail_url, $vimeo_id)) 
      $vmvideo_id = $vimeo_id[3]; 
      $hash = unserialize(file_get_contents("http://vimeo.com/api/v2/video/$vmvideo_id.php")); 
      $data->thumbnail_url = $hash[0]['thumbnail_large']; 
    } 

    if (! empty($data->thumbnail_url) && ! $this->_thumb_id) { 
     //if (in_array(@ $data->type, array('video'))) // Only set for video embeds 
      $this->set_thumb_by_url($data->thumbnail_url, @ $data->title); 
    } 
} 

回答

2

你需要做的是實際修改你的youtube如果聲明使其看起來$url而不是$data->thumbnail_url。這會導致您的preg_match()正確匹配,並且它會返回正確的$yt_videoid供您使用。

2

在這個環節還有如何更改WP的預設的解釋。 Featured Images & Post Thumbnails 我認爲你可能會發現有趣的,可能你不需要使用插件。 the_post_thumbnail('full'); // Original image resolution (unmodified)

在鏈接它的寫:WordPress的的 默認圖像大小「縮略圖」,「中等」,「大」和「全尺寸」(您上傳的圖片的原始大小)。這些圖像大小可以在「設置」>「媒體」下的「WordPress管理媒體」面板中進行配置。您也可以通過傳遞一個陣列,圖像尺寸定義自己的圖像大小:

he_post_thumbnail(); // Without parameter ->; Thumbnail 
the_post_thumbnail('thumbnail'); // Thumbnail (default 150px x 150px max) 
the_post_thumbnail('medium'); // Medium resolution (default 300px x 300px max) 
the_post_thumbnail('large'); // Large resolution (default 640px x 640px max) 
the_post_thumbnail('full'); // Original image resolution (unmodified) 
the_post_thumbnail(array(100, 100)); // Other resolutions (height, width) 

設置特色圖片輸出尺寸#SET的特色圖片輸出尺寸 要在當前主題的functions.php的使用文件。 可以使用set_post_thumbnail_size()通過按比例調整圖像設置默認特色圖片大小(即,不扭曲它):

set_post_thumbnail_size(50, 50); // 50 pixels wide by 50 pixels tall, resize mode 

通過裁剪圖像(從設置默認特色圖片大小的兩側,或從頂部和底部):

set_post_thumbnail_size(50, 50, true); // 50 pixels wide by 50 pixels tall, crop mode 

在這個環節你可以看到更多的代碼:https://developer.wordpress.org/reference/functions/the_post_thumbnail/

使用the_post_thumbnail()或相關函數時,默認情況下會使用'post-thumbnail'圖像大小,但可根據需要指定不同的大小。

其他鏈接我認爲你可以找到有趣的事情是這樣的:Image Size and Quality 但它更通用。

視頻以某種方式工作。當然,這取決於YouTube上視頻的質量,您可以決定要顯示多大。如果你不使用不同的媒體播放器,你將使用默認的YouTube播放器,你可以使用API​​來做你想做的事。

我希望我有幫助。

+0

我認爲你不能使用插件。並嘗試使用緩存WordPress的默認設置。此代碼不適用於插件。 –