【发布时间】:2014-07-17 22:10:13
【问题描述】:
您好,我想从 div 中获得以下结构,但除了 while 循环中的 div 之外,我无法做到这一点。我的目标是:
<div class="grid-12">
<img ...>
</div>
<div class="girid-12 parent clear-each-2">
<div class="grid-6>
<img ...>
</div>
<div class="grid-6>
<img ...>
</div>
</div><!-- close clear-each-2 -->
如何从 while 循环中排除 div clear-each-2?
我的代码:
<?php if( have_rows('the_gallery') ):
$i = 1;
while( have_rows('the_gallery') ): the_row();
// vars
$imageBig = get_sub_field('image_big');
$imageMedium = get_sub_field('image_medium');
$imageSmall = get_sub_field('image_small');
$titleB = $imageBig['title'];
$altB = $imageBig['title'];
$captionB = $imageBig['caption'];
$titleM = $imageMedium['title'];
$altM = $imageMedium['title'];
$captionM = $imageMedium['caption'];
$titleS = $imageSmall['title'];
$altS = $imageSmall['title'];
$captionS = $imageSmall['caption'];
?>
<?php if( $imageBig ): ?>
<div class="grid-12">
<img src="<?php echo $imageBig['url']; ?>" alt="<?php echo $altB['alt'] ?>" class="max-img" />
<div class="imgDescriptionSmall float-right"><strong><?php echo $titleB; ?></strong> <?php echo $captionB; ?></div>
</div>
<?php endif; ?>
<?php if( $imageMedium ): ?>
<div class="gird-12 parent clear-each-2">
<div class="grid-6 grid-mobile-12">
<img src="<?php echo $imageMedium['url']; ?>" alt="<?php echo $altM['alt'] ?>" class="max-img" />
<div class="imgDescriptionSmall float-right"><strong><?php echo $titleM; ?></strong> <?php echo $captionM; ?></div>
</div>
</div>
<?php endif; ?>
<?php if ($imageSmall):?>
<div class="grid-12 parent clear-each-3">
<div class="grid-4 grid-tablet-4 grid-mobile-12">
<img src="<?php echo $imageSmall['url']; ?>" alt="<?php echo $altS['alt'] ?>" class="max-img" />
<div class="imgDescriptionSmall float-right"><strong><?php echo $titleS; ?></strong> <?php echo $captionS; ?></div>
</div>
</div>
<?php endif; $i++; ?>
<?php endwhile; ?>
最好的,卡罗尔
【问题讨论】:
标签: wordpress while-loop repeater advanced-custom-fields