【发布时间】:2015-12-09 16:08:43
【问题描述】:
我使用 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's。
【问题讨论】:
-
最后一个标签使用 PHP 短代码打开标签,可能无效。虽然不确定 WP 的东西。
标签: php wordpress custom-fields advanced-custom-fields