在这段代码中,我有一个视频I数组,我在页面上使用集成的vimeo视频。一旦页面打开,视频就开始播放,当第一个视频完成后,第二个视频就开始播放。现在,我想在我的ACF字段中使用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>发布于 2017-11-10 16:56:13
ACF
$value = get_field( 'id_1', 300 );JS
id: videos[<?php echo $value; ?>],//first element发布于 2017-11-10 18:46:32
若要创建ID数组,请使用高级自定义字段Repeater Field。检查文档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;
?>https://stackoverflow.com/questions/47227524
复制相似问题