如何将 youtube 嵌入代码中的 youtube 缩略图设置为 wordpress 中的特色图片?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/17759526/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
How to set youtube thumbnail from youtube embed code as featured image in wordpress?
提问by Polo Pakina
How to set external url of youtube thumbnail (not uploading it inside my site) of an youtube video from iframe embed code of youtube video?
如何从 youtube 视频的 iframe 嵌入代码设置 youtube 视频的 youtube 缩略图的外部 url(不将其上传到我的网站内)?
Is it possible to make function which will pull external youtube thumbnail URL and set it as featured image from:
是否可以创建功能来提取外部 youtube 缩略图 URL 并将其设置为特色图片:
<iframe width="420" height="315" src="www.youtube.com/embed/gTp4sZtjHS" frameborder="0" allowfullscreen></iframe>
Do not ask about OEmbed or similar things, I think question is clear.
不要问 OEmbed 或类似的东西,我认为问题很清楚。
回答by phil
The format for pulling the large image from a YouTube video is this http://img.youtube.com/vi/A4a0xZMMlqE/0.jpg
just replace "A4a0xZMMlqE" with the video id.
从 YouTube 视频中提取大图像的格式是http://img.youtube.com/vi/A4a0xZMMlqE/0.jpg
将“A4a0xZMMlqE”替换为视频 ID。
I think the easiest way to set this up would be to forget about using it as a featured image but just pulling it into the template dynamically.
我认为设置它的最简单方法是忘记将其用作特色图像,而只是将其动态拉入模板。
So in your post, make a custom field that will hold the YouTube video ID and in the template do something like:
因此,在您的帖子中,创建一个包含 YouTube 视频 ID 的自定义字段,并在模板中执行以下操作:
<img src="http://img.youtube.com/vi/<?php echo get_post_meta($post->ID,'youtubeId');?>/0.jpg"/>
Does that solve your problem?
这能解决你的问题吗?
Otherwise if you're looking at really making it the featured image then you're probably looking at developing a custom plugin: http://net.tutsplus.com/tutorials/wordpress/creating-a-custom-wordpress-plugin-from-scratch/which will most likely make use of wp_insert_attachment
否则,如果您正在考虑真正将其作为特色图片,那么您可能正在考虑开发自定义插件:http: //net.tutsplus.com/tutorials/wordpress/creating-a-custom-wordpress-plugin-from -scratch/最有可能使用wp_insert_attachment
I also just found media_sideload_imagewhich I wasn't aware of. It will pull an image from a URL (i.e. the youtube link above) and attach it to a post.
我也刚刚发现了我不知道的media_sideload_image。它将从 URL(即上面的 youtube 链接)中提取图像并将其附加到帖子中。