doumiebiao6827 2012-07-09 20:40
浏览 33
已采纳

限制值数组的结果

I am using advanced custom fields in Wordpress. Without going into the details of how it works, I have a "repeater field" which lets the users add as many images to an aera of the backend as they please. To show these images, I use the following code (inside wordpress loop)

<?php if(get_field('slider_images')): ?>
<?php while(the_repeater_field('slider_images')): ?>
     <?php 
     $attachment_id = get_sub_field('work_slider_image'); 
     $size = "homepage";  
     $image = wp_get_attachment_image_src( $attachment_id, $size ); 
     echo $image[0]; 
     ?>
<?php endwhile; endif; ?>

The goal here is to create an array of image URLS and to only display the FIRST one. On other pages they will all be used, but on this page, I want to grab ONLY the first image, hence the echo $image[0];

For some reason, it is showing all of the uploaded images, and when I print the variable $image, it returns:

Array ( [0] => http://sitename.com/agsinfo/wp-content/uploads/2012/07/1.jpg [1] => 392 [2] => 165 [3] => )

After seeing this, it would make sense to me that echo $image[0]; would work, but for some reason its not. Any ideas?

  • 写回答

1条回答 默认 最新

  • doucuo1642 2012-07-09 20:50
    关注
        <?php if(get_field('slider_images')): ?>
    <?php while(the_repeater_field('slider_images')): ?>
         <?php 
         $attachment_id = get_sub_field('work_slider_image'); 
         $size = "homepage";  
         $image[] = wp_get_attachment_image_src( $attachment_id, $size ); 
    
         ?>
    <?php endwhile;
     echo $image[0];
     endif;  ?>
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 执行 virtuoso 命令后,界面没有,cadence 启动不起来
  • ¥50 comfyui下连接animatediff节点生成视频质量非常差的原因
  • ¥20 有关区间dp的问题求解
  • ¥15 多电路系统共用电源的串扰问题
  • ¥15 slam rangenet++配置
  • ¥15 有没有研究水声通信方面的帮我改俩matlab代码
  • ¥15 ubuntu子系统密码忘记
  • ¥15 保护模式-系统加载-段寄存器
  • ¥15 电脑桌面设定一个区域禁止鼠标操作
  • ¥15 求NPF226060磁芯的详细资料