在这段代码中,我有一个视频ID数组,我在页面上使用了集成的vimeo视频。页面打开后,视频开始播放,第一个视频完成后,第二个视频开始播放。现在,我想在我的ACF字段中使用id write。 在我的代码的第一部分,我试着看看他是否采用了正确的ID。 但我有一些难以改变我的代码使用get_field();与数组。
<?php
if ( !function_exists('get_field') ) return;
$value = get_field( "id_1", 300 );
if ( $value) : the_field('id_1');
endif;
?>
<div id="headervideo" class="videoClass"></div>
<script src="https://player.vimeo.com/api/player.js"></script>
<script>
document.addEventListener("DOMContentLoaded", function(event) {
var videos = [ '240466644', '146661000']; //Array videos ids
var options = {
id: videos[0],//first element
width: 700,
height: 500,
loop: false
};
player = new Vimeo.Player('headervideo', options);
player.play()
playMovie(videos, 0, true)
})
var playMovie = function(videos, currentVideoIdx, first) {
if (!first) {
player.loadVideo(videos[currentVideoIdx % videos.length]).then(function(id) {
player.play()
}).catch(function(error) {});
player.on('ended', function() {
playMovie(videos, ++currentVideoIdx, false)
});
}
</script>
答案 0 :(得分:0)
ACF
id: videos[<?php echo $value; ?>],//first element
JS
if (y >= 70 && y <= 210 && x >= 280) {
x = 250;
}
答案 1 :(得分:0)
要创建ID数组,请使用高级自定义字段转发器字段。查看文档https://www.advancedcustomfields.com/resources/repeater/
然后从那里看起来就像这样......
<?php
// check if the repeater field has rows of data
if( have_rows('repeater_field_name') ):
// loop through the rows of data
while ( have_rows('repeater_field_name') ) : the_row();
// get the sub field value
$value = get_sub_field('sub_field_name');
endwhile;
else :
// no rows found
endif;
?>