- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
当fb_video字段在帖子编辑器中包含链接并在博客供稿页面和iframe中显示视频图像时,我正在使用一个名为gridby for wordpress的主题,该主题使用其自己的插件将特色图片更改为vimeo或youtube的iframe。在帖子中,而不是精选图片。到目前为止,我仅将其用于vimeo链接,该链接可以正常工作,而今天,我尝试插入一个结尾为/ embed的youtube视频链接,但没有并且仍然显示错误。它不是我的代码,所以如果有人需要我的帮助,那么我就不想再刹车了。我将iframe放入编辑器中的空白帖子中,但没有通过PHP代码显示,但显示良好。
/* ------------------------------------------------------------------------- *
* Video Functions
/* ------------------------------------------------------------------------- */
/* display url image big youtube and vimeo
/* ------------------------------------ */
if ( !function_exists('video_image') ) {
function video_image($url, $size){
$image_url = parse_url($url);
if($size == 'small') {
if($image_url['host'] == 'www.youtube.com' || $image_url['host'] == 'youtube.com'){
$array = explode("&", $image_url['query']);
return "http://img.youtube.com/vi/".substr($array[0], 2)."/1.jpg";
} else if($image_url['host'] == 'www.vimeo.com' || $image_url['host'] == 'vimeo.com'){
$hash = unserialize(file_get_contents("http://vimeo.com/api/v2/video/".substr($image_url['path'], 1).".php"));
return $hash[0]["thumbnail_small"];
}
} else if($size == 'hd') {
if($image_url['host'] == 'www.youtube.com' || $image_url['host'] == 'youtube.com'){
$array = explode("&", $image_url['query']);
return "http://img.youtube.com/vi/".substr($array[0], 2)."/hqdefault.jpg";
} else if($image_url['host'] == 'www.vimeo.com' || $image_url['host'] == 'vimeo.com'){
$hash = unserialize(file_get_contents("http://vimeo.com/api/v2/video/".substr($image_url['path'], 1).".php"));
return $hash[0]["thumbnail_large"];
}
}
}
}
/* display iframe of youtube and vimeo
/* ------------------------------------ */
if ( !function_exists('video_player') ) {
function video_player($url, $autoplay){
$image_url = parse_url($url);
if($autoplay == '1') {
if($image_url['host'] == 'www.youtube.com' || $image_url['host'] == 'youtube.com'){
$array = explode("&", $image_url['query']);
return "<iframe title='YouTube video player' width='400' height='275' src='http://www.youtube.com/embed/".substr($array[0], 2)."?wmode=trasparent&autoplay=1' frameborder='0' wmode='opaque' allowfullscreen></iframe>";
} else if($image_url['host'] == 'www.vimeo.com' || $image_url['host'] == 'vimeo.com'){
return "<iframe src='http://player.vimeo.com/video/".substr($image_url['path'], 1)."?autoplay=true' width='400' height='275' frameborder='0' allowfullscreen'></iframe>";
}
} else {
if($image_url['host'] == 'www.youtube.com' || $image_url['host'] == 'youtube.com'){
$array = explode("&", $image_url['query']);
return "<iframe title='YouTube video player' width='400' height='275' src='http://www.youtube.com/embed/".substr($array[0], 2)."?wmode=trasparent' frameborder='0' wmode='opaque' allowfullscreen></iframe>";
} else if($image_url['host'] == 'www.vimeo.com' || $image_url['host'] == 'vimeo.com'){
return "<iframe src='http://player.vimeo.com/video/".substr($image_url['path'], 1)."' width='400' height='275' frameborder='0' allowfullscreen'></iframe>";
}
}
}
}
/* ------------------------------------------------------------------------- *
* Filter Thumbnail
/* ------------------------------------------------------------------------- */
add_filter( 'post_thumbnail_html', 'post_thumbnail_html', 10, 3 );
function post_thumbnail_html( $html, $post_id, $post_image_id) {
$video = get_post_meta( $post_id, 'fb_video', true );
if ($html) { /* If have thumbnail image set */
if ($video != '') {
if (is_single()){ /* Show playe on single page */
if( function_exists('video_player')) {
?>
<div class='video-container'><?php echo video_player($video, 0); ?></div>
<?php
}
} else {
echo '<i class="fa fa-play-circle fa-4x"></i>'. $html;
}
} else {
echo $html;
}
} else { /* If haven't thumbnail image set */
if ($video != '') {
if (is_single()){ /* Show playe on single page */
if( function_exists('video_player')) {
?>
<div class='video-container'><?php echo video_player($video, 0); ?></div>
<?php
}
} else {
echo '<i class="fa fa-play-circle fa-4x"></i><img class="img-res" src="'. video_image($video, 'hd').'" alt="' . esc_attr( get_post_field( 'post_title', $post_id ) ) . '" />';
}
}
}
}
?>
最佳答案
必须使用网址的/ watch?v =版本才能使其显示。我有一个与此有关的问题,问用户在自定义字段中输入youtube的ID是否会更容易?这样,您可以将iframe放入页面模板中,并使用get meta函数将其插入/后面。
那就是我将如何输入视频本身,但是我将如何以这种方式在博客页面帖子中获取视频图像?没看到需要插件的情况,我真的想在自己的主题中使用此功能,因此正在寻找更清洁的替代方法
关于javascript - YouTube嵌入和PHP显示iframe但显示错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42677962/
是否有任何解决方案来禁用右键单击选项并从 Youtube 视频中删除右下角水印 Logo ?我在搜索 GOOGLE 后尝试过。谁能告诉我? 谢谢你。 最佳答案 试试 modestbranding范围:
我想使用 YouTube API (v3) 来启用仅音乐轨道的搜索(没有猫或藤蔓或任何其他非音乐视频)。我查看了 API Explorer 和文档以获取有关该问题的任何指示,但找不到任何有用的信息。
我需要为网站使用YouTube视频缩略图的maxresdefault版本,但是在开发实现此目的的代码后,我发现并非所有视频都具有这些缩略图,尽管这些视频均为1080p。 有没有一种方法可以自动为我的所
我想通过“iframe”嵌入youtube视频,但YouTube在我国禁止使用,建议我如何在我的网站上嵌入视频! [1]:以下图片显示了在我的国家/地区无法访问youtube 最佳答案 该视频将被嵌入
我正在为myBB使用一个名为Profile Music Plugin的插件,可以在此处找到http://community.mybb.com/mods.php?action=view&pid=75 我
Youtube IFRAME API中是否有可以执行命令的功能,例如在播放的视频结尾处打开网站? (我相信有一个功能可以在旧的Java API下执行此操作,但该功能已于去年弃用。) 最佳答案 您可以引
我试图在Videos.insert和Videos.update查询中设置3d尺寸标志。但是标志不会改变。 更新查询示例: 请求: PUT https://www.googleapis.com/yout
使用此获取评论 评论主题:列表 GET https://www.googleapis.com/youtube/v3/commentThreads?part=snippet { "error": {
最近,我尝试使用OEmbed服务通过播放列表查询参数获取视频网址的iframe代码,但是OEmbed为我们提供了与我要求的视频不同的iframe代码。 这是带有播放列表查询参数的视频网址: https
我正在使用此代码: https://www.googleapis.com/youtube/v3/search?q=global+warming&part=id&maxResults=50&key=MY
我有一个LiveBroadcast,并且将来会添加一个scheduledStartTime。据我所知,这次测试不会对LiveBroadcast的整体状态产生影响,即广播是否具有准备就绪/测试的life
YouTube API是否支持在特定时间后关闭浏览器的参数? 这需要使用链接在不同位置共享来推广促销视频。视频播放结束后关闭浏览器。 最佳答案 您可以使用Youtube API监控视频是否播放完毕,然
如果没有表单上的透明面板,YouTube Player将可以正常播放视频,或者可以全屏播放视频,透明面板中有一些图像没有什么特别的。如果我取出透明面板,则YouTube播放器会按需工作,并嵌入到应用程
我正在通过Google进行身份验证,以尝试获取YouTube分析数据,但我的问题是我不知道在查询YouTube时如何向您填充参数 在这里,我正在提供一项新服务:然后尝试查询它 我不确定要在“ids”参
我想添加youtube视频列表,但不添加视频播放器。所以我需要的是 视频标题 视频缩略图 视频时长 我以某种方式设法通过使用此http://img.youtube.com/vi/4wew2uWoARw
我正在使用youtube api和python库gdata 我遵循了文档,但似乎没有出路。 问题是 - How do i get the size of the youtube video fil
使用Youtube API,我如何获得评论或顶过youtube视频的用户ID /处理列表? 提前致谢 最佳答案 在这里,您可以了解如何使用YouTube API v2(v3尚不支持此注释)获取评论:h
我正在为所有相关数据构建一个仪表板(以php为单位),我还想在YouTube“稍后观看”播放列表中显示我的商品数量。 我知道无法使用YouTube API来解决这个问题,但是也许有人想出一种解决方法?
我尝试使用YouTube API,但存在引号问题。 SearchResource.ListRequest searchListRequest = yt.Search.List("sni
我想为我的Android应用程序的用户构建视频推荐器。我有Google OAuth可以登录我的应用程序。我可以获取有关我的应用程序用户在YouTube上观看的视频的数据吗? 最佳答案 v3 API分为
我是一名优秀的程序员,十分优秀!