doufenyu7610 2018-06-11 07:00
浏览 42
已采纳

带有图像的ACF中继器,仅显示一些自定义CSS的前3个图像

I have a custom image field in my website about page its like a small gallery with different sized images. I don't want to loop through with all images I want to display 3 images in different column by order. How could i do that? any help would be appreciated. Here I am providing my code which doesn't work.

 <div class="row fm-about-gallery-grid">
     <?php if( have_rows('fima_check_courses_images') ): ?>
     <?php while(have_rows('fima_check_courses_images')): the_row();
     $fima_check_courses_image = get_sub_field('fima_check_courses_image');
      ?>
        <div class="col-sm-7">
           <div class="fm-about-gallery-image">
            <?php if($fima_check_courses_image):?>
       <img alt="" src="<?php echo $fima_check_courses_image[0]['url']; ?>">
            <?php endif; ?>
            </div>
         </div>
         <div class="col-sm-5">
         <div class="fm-about-gallery-image">
       <img alt="" src="<?php echo $fima_check_courses_image[0]['url']; ?>">
         </div>
         </div>
       <div class="col-sm-12">
       <div class="fm-about-gallery-image">
     <img alt="" src="<?php echo $fima_check_courses_image[0]['url']; ?>">
       </div>
       </div>
       <?php endwhile; ?>
       <?php endif; ?>
  </div>
  • 写回答

1条回答 默认 最新

  • duanjiaoxi4928 2018-06-11 07:16
    关注

    You can do using following code. Here i use css classes array and counter which help you achieve your functionality.

       <div class="row fm-about-gallery-grid">
           <?php if( have_rows('fima_check_courses_images') ): ?>
           <?php 
             $classarray=array("col-sm-7","col-sm-5","col-sm-12"); // add columns classes
             $index=0; //counter
             while(have_rows('fima_check_courses_images')): the_row();
             $fima_check_courses_image = get_sub_field('fima_check_courses_image');
    
      ?>
        <div class="col-sm-<?php echo $classarray[$index];?>">
           <div class="fm-about-gallery-image">
            <?php if($fima_check_courses_image):?>
       <img alt="" src="<?php echo $fima_check_courses_image['url']; ?>">
            <?php endif; ?>
            </div>
         </div>       
    
       <?php 
       $index++; 
       if($index==3) break;
       endwhile; ?>
       <?php endif; ?>
       </div>
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 #MATLAB仿真#车辆换道路径规划
  • ¥15 java 操作 elasticsearch 8.1 实现 索引的重建
  • ¥15 数据可视化Python
  • ¥15 要给毕业设计添加扫码登录的功能!!有偿
  • ¥15 kafka 分区副本增加会导致消息丢失或者不可用吗?
  • ¥15 微信公众号自制会员卡没有收款渠道啊
  • ¥100 Jenkins自动化部署—悬赏100元
  • ¥15 关于#python#的问题:求帮写python代码
  • ¥20 MATLAB画图图形出现上下震荡的线条
  • ¥15 关于#windows#的问题:怎么用WIN 11系统的电脑 克隆WIN NT3.51-4.0系统的硬盘