o嵌入特色图片(大缩略图)

oEmbed Featured Image (Large Thumbnail)

我找到了一个名为 oEmbed Featured Image 的插件,除了输出最大尺寸外,它绝对可以满足我的所有需求。

该插件的默认 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 );
    }
}

在这个 link 中有关于如何更改 wp 预设的说明。 Featured Images & Post Thumbnails 我想你会发现有趣的,可能你不需要使用插件。 the_post_thumbnail( 'full' ); // Original image resolution (unmodified)

在 link 中写着: 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 the Featured Image Output Size 在当前主题的 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

在此link中您可以看到更多代码:https://developer.wordpress.org/reference/functions/the_post_thumbnail/

当使用 the_post_thumbnail() 或相关函数时,默认使用“post-thumbnail”图像大小,但可以根据需要指定不同的大小.

其他link我想你会发现有趣的是:Image Size and Quality 但它更通用。

视频以某种方式工作。当然取决于 youtube 中视频的质量,您可以决定要显示多大。如果你不使用不同的媒体播放器,你将使用默认的 youtube 播放器,你可以使用 API 来做你想做的事。

希望对您有所帮助。

您需要做的实际上是修改 youtube if 语句,使其查看 $url,而不是 $data->thumbnail_url。这将使您的 preg_match() 正确匹配,并且 return 正确的 $yt_videoid 供您使用。