我已经设置了一个自定义字段,您可以通过wordpress中的文本窗口小部件将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&showinfo=0" frameborder="0" allowfullscreen></iframe>
</div>
<?php
}
}
} ?>
我已经在内容中添加了这一点,但似乎什么都没有显示。有人能帮我找出虫子吗。。
Youtube视频显示在wordpress模板中使用高级自定义字段
1) 在acf中创建文本字段。示例:文本字段名称为video_url
2) 请在acf文本字段中输入youtube视频链接。
3) 显示wordpress模板页面中的任何位置
<?php // use inside loop
echo $youtubevideo_code = wp_oembed_get( get_field('video_url') );
?>