如何在视频中使用高级自定义字段

how to use Advanced Custom Fields with videos

在这段代码中,我有一个视频 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>

ACF

$value = get_field( 'id_1', 300 );

JS

id: videos[<?php echo $value; ?>],//first element

要创建 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;

?>