php ACF中继器阵列片
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了php ACF中继器阵列片相关的知识,希望对你有一定的参考价值。
<?php $i = 1; if ( have_rows('imagelinks') ) : ?>
<div class="row">
<div class="col-xs-12 col-sm-11 col-sm-offset-1 col-md-11 col-md-offset-1 col-lg-10 col-lg-offset-2">
<div id="featured-links" class="section">
<div class="imagelink-custom">
<?php while ( have_rows('imagelinks') ) : the_row(); ?>
<?php
$image = get_sub_field('image');
$link = get_sub_field('link');
$buttonText = get_sub_field('button_text');
?>
<div>
<a href="<?php echo $link; ?>">
<img src="<?php echo $image['url']; ?>" alt="<?php echo $image['alt']; ?>" class="img-responsive">
<span class="img-link-title"><?php echo $buttonText; ?></span>
</a>
</div>
<?php if ( $i === 2 ) : ?>
<?php echo '</div><div class="imagelink-custom second-row">'; ?>
<?php endif; ?>
<?php $i++; endwhile; ?>
</div>
</div>
</div>
<!-- /end main row -->
</div>
<?php endif; ?>
<?php $i = 1; if ( have_rows('imagelinks') ) : while ( have_rows('imagelinks') ) : the_row(); ?>
<?php
$image = get_sub_field('image');
$link = get_sub_field('link');
$buttonText = get_sub_field('button_text');
array_push(
$array, array(
'img_src' => $image['url'],
'img_alt' => $image['alt'],
'link_to' => $link,
'button' => $buttonText
)
);
?>
<?php endwhile; endif; ?>
<?php
$firstRow = array_slice($array, 0, 2);
$secondRow = array_slice($array, 2, 4);
if ( $firstRow ) {
echo '<div class="imagelink-custom">';
foreach ( $firstRow as $first ) {
echo '<div>';
echo '<a href="' . $first['link_to'] . '">';
echo '<img src="' . $first['img_src'] . '" alt="' . $first['img_alt'] . '" class="img-responsive">';
echo '<span class="img-link-title">' . $first['button'] . '</span>';
echo '</a>';
echo '</div>';
}
echo '</div>';
}
if ( $secondRow ) {
echo '<div class="imagelink-custom second-row">';
foreach ( $secondRow as $second ) {
echo '<div>';
echo '<a href="' . $second['link_to'] . '">';
echo '<img src="' . $second['img_src'] . '" alt="' . $second['img_alt'] . '" class="img-responsive">';
echo '<span class="img-link-title">' . $second['button'] . '</span>';
echo '</a>';
echo '</div>';
}
echo '</div>';
}
?>
以上是关于php ACF中继器阵列片的主要内容,如果未能解决你的问题,请参考以下文章
php 准备使用ACF中继器
php ACF - 中继器
php ACF中继器
php ACF中继器场分页
php ACF中继器场分页
php 将重力表单列表保存到ACF中继器