[英]ACF WordPress. Echo field in repeater field if not empty
I use ACF repeater field and I try to echo link if it not empty. 我使用ACF转发器字段,如果不为空,则尝试回显链接。 My code
我的密码
<?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();?>
What I doing wrong, help me please) May be the reason is 2 loops with same name? 我做错了,请帮我)可能是2个名称相同的循环的原因? To be more clear: I have 1 repeater field with name
repeater_field_name
and 5 sub fields in row. 更清楚地说:我有1个名称为
repeater_field_name
器字段,并且在行中有5个子字段。 Fifth sub field I need to use for 1 .fr-slide-item
and display there audio player. 第五子字段,我需要使用1
.fr-slide-item
并在其中显示音频播放器。 In that row I give the link to audio file, for all other rows that sub field is empty. 在该行中,我提供了指向音频文件的链接,对于所有其他行,子字段为空。 I need to display that one, no in all
.fr-slide-item
's. 我需要显示一个,在所有
.fr-slide-item
中都不显示。
You can use the standard repeater field markup (for the most part) to do this. 您可以使用标准中继器字段标记(大部分情况下)来执行此操作。
For example: 例如:
<?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; ?>
I do that with code: 我用代码做到这一点:
<?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.