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>
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥20 关于#硬件工程#的问题,请各位专家解答!
  • ¥15 关于#matlab#的问题:期望的系统闭环传递函数为G(s)=wn^2/s^2+2¢wn+wn^2阻尼系数¢=0.707,使系统具有较小的超调量
  • ¥15 FLUENT如何实现在堆积颗粒的上表面加载高斯热源
  • ¥30 截图中的mathematics程序转换成matlab
  • ¥15 动力学代码报错,维度不匹配
  • ¥15 Power query添加列问题
  • ¥50 Kubernetes&Fission&Eleasticsearch
  • ¥15 報錯:Person is not mapped,如何解決?
  • ¥15 c++头文件不能识别CDialog
  • ¥15 Excel发现不可读取的内容