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条)

报告相同问题?

悬赏问题

  • ¥15 如何用stata画出文献中常见的安慰剂检验图
  • ¥15 c语言链表结构体数据插入
  • ¥40 使用MATLAB解答线性代数问题
  • ¥15 COCOS的问题COCOS的问题
  • ¥15 FPGA-SRIO初始化失败
  • ¥15 MapReduce实现倒排索引失败
  • ¥15 ZABBIX6.0L连接数据库报错,如何解决?(操作系统-centos)
  • ¥15 找一位技术过硬的游戏pj程序员
  • ¥15 matlab生成电测深三层曲线模型代码
  • ¥50 随机森林与房贷信用风险模型