duandie0884 2016-07-11 21:01
浏览 70
已采纳

在while语句中显示每两个div的容器

I'm using foundation and Wordpress with Advanced Custom Field to build a services module.

I'm using the repeater field to insert the data.

Currently I have the row element outside of the while loop.

I need the div row to wrap every two "small-6 columns tgs-single-service" divs so the foundation grid displays properly. If I insert the row div in the while statement, it will wrap every single div in a row, which I do not want.

<?php if( have_rows('services_content') ): 
    $classNumber = 0

?>
    <section class="full-width tgs-services-section">
        <div class="row">
        <?php while( have_rows('services_content') ): the_row(); ?>
             <div class="small-6 columns tgs-single-service-<?php echo $classNumber = $classNumber + 1 ?>">
                 <figure class="effect-goliath">
                 <?php while( have_rows('service_images') ): the_row(); ?>
                 <img src="<?php the_sub_field('small_image');?>" srcset="<?php the_sub_field('medium_image');?> 1000w, <?php the_sub_field('large_image');?> 2000w" alt="Byoungz Poet Logo">
                 <?php endwhile; ?>
                <figcaption>
                     <h3><?php the_sub_field('service_title');?></h3>
                     <?php the_sub_field('service_text');?>
                    </figcaption>   
                 </figure>
             </div><!-- end service section -->
        <?php endwhile; ?>
        </div><!--end row -->
    </section>
<?php endif; ?>

Currently this displays as:

<div class="row">
  <div class="small-6 columns tgs-service-section-1"></div>
  <div class="small-6 columns tgs-service-section-2"></div>
  <div class="small-6 columns tgs-service-section-3"></div>
  <div class="small-6 columns tgs-service-section-4"></div>
</div>

I would like to achieve

<div class="row">
  <div class="small-6 columns tgs-service-section-1"></div>
  <div class="small-6 columns tgs-service-section-2"></div>
</div>
<div class="row">
  <div class="small-6 columns tgs-service-section-3"></div>
  <div class="small-6 columns tgs-service-section-4"></div>
</div>

Is there a way to have row wrap every two tgs-single-service divs?

  • 写回答

3条回答 默认 最新

  • 普通网友 2016-07-11 21:20
    关注
    <section class="full-width tgs-services-section">
        <div class="row">
        <!-- Create a counter i -->
        <?php $i=1; while( have_rows('services_content') ): the_row(); ?>
             <div class="small-6 columns tgs-single-service-<?php echo $classNumber = $classNumber + 1 ?>">
                 <figure class="effect-goliath">
                 <?php while( have_rows('service_images') ): the_row(); ?>
                 <img src="<?php the_sub_field('small_image');?>" srcset="<?php the_sub_field('medium_image');?> 1000w, <?php the_sub_field('large_image');?> 2000w" alt="Byoungz Poet Logo">
                 <?php endwhile; ?>
                <figcaption>
                     <h3><?php the_sub_field('service_title');?></h3>
                     <?php the_sub_field('service_text');?>
                    </figcaption>   
                 </figure>
             </div><!-- end service section -->
             <?php if($i % 2 == 0): ?><!-- Check if its divisable by 2 -->
                </div>
                <div class="row">
            <?php endif; ?>
            <?php $i++; ?>
        <?php endwhile; ?>
        </div><!--end row -->
    </section>
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(2条)

报告相同问题?

悬赏问题

  • ¥30 自适应 LMS 算法实现 FIR 最佳维纳滤波器matlab方案
  • ¥15 lingo18勾选global solver求解使用的算法
  • ¥15 全部备份安卓app数据包括密码,可以复制到另一手机上运行
  • ¥15 Python3.5 相关代码写作
  • ¥20 测距传感器数据手册i2c
  • ¥15 RPA正常跑,cmd输入cookies跑不出来
  • ¥15 求帮我调试一下freefem代码
  • ¥15 matlab代码解决,怎么运行
  • ¥15 R语言Rstudio突然无法启动
  • ¥15 关于#matlab#的问题:提取2个图像的变量作为另外一个图像像元的移动量,计算新的位置创建新的图像并提取第二个图像的变量到新的图像