2017-03-08 4 views
0

wordpressにgridbyというテーマを使用しています。これは、fb_videoフィールドに投稿エディタでリンクが表示されているときに特集した画像をvimeoまたはyoutubeのiframeに変更しますフィーチャーされた画像の代わりにビデオフィードをブログフィードページとポストのiframeに表示します。私はこれまでにvimeoのリンクを使っていましたが、これはうまくいきました。そして、今日、最後に/ embedとyoutubeのビデオリンクを入れようとしましたが、エラーが表示されずにいます。それは私のコードではないので、もし私がこの機能を必要とするように誰かが私の偉大さを助けることができれば、さらにそれを制動したくない。私はエディタの空白のポストにiframeを置くと、PHPコードで表示されないように表示されます。Youtube埋め込みとPHPでiframeを表示しているのに表示エラーがある

/* ------------------------------------------------------------------------- * 
* 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)) . '" />'; 

       } 

      } 

     } 

    } 



?> 

答えて

0

は、表示するには/ watch?v = urlのバージョンを使用する必要がありました。質問これについては、カスタムフィールドにyoutubeのidを入力するようにユーザーに求めるのは簡単ではないでしょうか?あなたはちょうどページテンプレートにiframeを入れ、getメタ関数を使って/?の後に挿入することができます。

私はビデオ自体をどのように入力するのですか?しかし、ブログページの投稿のようにビデオのイメージを取得するにはどうすればいいですか?本当に私はあなたがIFRAMEの問題を解決するのを助けることができるクリーナー代替

0

https://wordpress.org/plugins/optimise-youtube-video-embed/

このプラグインを探して、私自身のテーマでこの機能を使用したいプラグインの必要性を参照してくださいいけません。これにより、ページの負荷が動的に増加します。ボタンをクリックすると、あなたのビデオだけが埋め込まれます。

あなたのページや投稿にショートコードを含めてください。カスタム画像をビデオバナーとして追加できます。

[eh_optimize_youtube_embed video="youtube_link" banner="banner_image_link_optional"] 
関連する問題