【发布时间】:2015-03-19 01:33:02
【问题描述】:
我已经设置了一个自定义字段,您可以通过 wordpress 中的文本小部件在其中添加 youtube 链接的结尾,然后一个函数将其添加到 url 中的 iframe。
下面是添加这个到页面的函数:
<?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&showinfo=0" frameborder="0" allowfullscreen></iframe>
</div>
<?php
}
}
} ?>
我已将其添加到内容中,但似乎仍然没有显示任何内容。有人可以帮我找出任何错误..
【问题讨论】:
-
$videoId 返回什么
-
检查 iframe 的
srcurl 并匹配,是否是预期的 youtube url...
标签: php wordpress youtube advanced-custom-fields