ACF WordPress.中继器字段中的回波字段,如果不为空


ACF WordPress. Echo field in repeater field if not empty

我使用ACF中继器字段,如果它不是空的,我尝试回显链接。我的代码

<?php global $query_string;
        $frs = query_posts($query_string.'&page=myCustomPage'); ?>
        <?php $frslides=get_field('repeater_field_name'); ?>
        <div class="fr-slider-links">
        <?php foreach($frslides as $frslide){?>
            <a href="#"><?php echo $frslide['sub_field1']; ?></a>
        <? } ?>
        </div><!-- fr-slider-links -->
    <div class="fr-slider-wrapper">
        <div id='dial'>
            <button class='left' type='button'></button>
            <button class='right' type='button'></button>
            <div class='content'></div>
            <?php $i = 1; ?>
            <?php foreach($frslides as $frslide){?>
                <div class='fr-slide-item'>
                <div class='icon sl-icon-<?php echo $i; ?>'></div>
                <div class='dial-content'>
                    <h3><?php echo $frslide['sub_field2']; ?></h3>
                    <div class="slider-box cf">
                        <img src="<?php echo $frslide['sub_field3']; ?>" height="121" width="121" alt="">
                        <p><?php echo $frslide['sub_field4']; ?></p>
                        <?php // Setup the standard repeater loop.
                            if ( have_rows( 'repeater_field_name' ) ) : while ( have_rows( 'repeater_field_name' ) ) : the_row();
                                if ( $source_link = get_sub_field( 'link_to_audio' ) ) : ?>
                                <audio controls>
                                    <source src="<?php echo esc_url( $source_link ); ?>" type="audio/ogg; codecs=vorbis">
                                    <source src="<?php echo esc_url( $source_link ); ?>" type="audio/mpeg"> 
                                </audio>
                                <?php endif; 
                        endwhile; endif; ?> 
                    </div><!-- slider-box -->
                </div>
                </div><!-- item -->
                <?php $i++;?>
            <? } ?>
        </div><!-- dial -->
        <?php wp_reset_query();?>

我做错了什么,请帮助我)可能是原因是2循环相同的名称?更清楚地说:我有一个中继器字段与名称repeater_field_name和5子字段一行。第五子字段,我需要使用1 .fr-slide-item和显示那里的音频播放器。在那一行中,我给出了音频文件的链接,对于所有其他行,子字段为空。我需要显示那个,而不是所有的.fr-slide-item

您可以使用标准的中继器字段标记(在大多数情况下)来完成此操作。

例如:

<?php // Setup the standard repeater loop.
if ( have_rows( 'repeater_field_name' ) ) : while ( have_rows( 'repeater_field_name' ) ) : the_row();
    // Check if a link has been set and assign it to a variable.
    if ( $source_link = get_sub_field( 'link_field' ) ) : ?>
        <audio controls>
            <source src="<?php echo esc_url( $source_link ); ?> . . .
            . . . 
        </audio>
    <?php endif; 
endwhile; endif; ?> 

我用代码:

<?php $frslides=get_field('repeater_field_name'); ?>
<?php foreach($frslides as $frslide){?>
     <?php if( $frslide['link_field'] ): ?>
    <audio controls class="fr-audio">
    <source src="<?php echo $frslide['link_field']; ?>" type="audio/ogg; codecs=vorbis">
    <source src="<?php echo $frslide['link_field']; ?>" type="audio/mpeg">
    </audio>
<?php endif; ?>
<? } ?>