簡體   English   中英

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個名稱相同的循環的原因? 更清楚地說:我有1個名稱為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; ?>
<? } ?>

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM