2015-03-19 76 views
1

我已經設置了一個自定義字段,您可以通過wordpress中的文本小部件添加youtube鏈接的結尾,然後從此處將函數添加到url中的iframe 。高級自定義字段 - 在Woocommerce模板上顯示YouTube視頻

下面是功能附加此頁面:

   <?php if (($videoUrl = get_field('video_name', $post->ID)) != '') { 
      //Extract the url arguments (everything after the '?' 
      if (($query = parse_url($videoUrl, PHP_URL_QUERY)) != '') { 
       //Convert the arguments into an array for each access 
       parse_str($query, $arguments); 
       if (array_key_exists('v', $arguments)) { 
        //Create the embed code using the id from the 'v' argument 
        $videoId = $arguments['v']; 
        ?> 
      <div class="videoContainer"> 
       <iframe width="390" height="219" src="https://www.youtube.com/embed/<?= $videoId ?>?rel=0&amp;showinfo=0" frameborder="0" allowfullscreen></iframe> 
      </div> 
      <?php 
     } 
    } 
} ?> 

我加入這個與內容然而,似乎沒有任何可以顯示靜止。可能有人請採用了先進的自定義字段幫助我發現任何錯誤。在WordPress模板

+0

是什麼$ VideoID的返回 – 2015-03-19 01:47:16

+0

檢查iframe和比賽的'src' URL,無論是預計YouTube網址或不... – 2015-03-19 04:25:49

回答

2

的Youtube視頻節目

1)在ACF創建文本字段。 例如:文本字段名稱是video_url

2)請在acf文本字段中輸入youtube視頻鏈接。

3)在任何地方展示在WordPress的模板頁面

<?php // use inside loop 
echo $youtubevideo_code = wp_oembed_get(get_field('video_url')); 
?> 
相關問題