具有转发器图像字段的多个div

时间:2012-10-17 13:39:04

标签: php javascript jquery ajax wordpress

我正在尝试使用转发器字段(ACF插件)的图像显示多个div。

例如Div 1带有图像1 - Div 2带有图像2 - 等等......

使用此标记:

<div id="project" class="item">
     <a href="#">
        <img src="img/project1.jpg" alt="project1" width="240" height="173">
     </a>
     <div class="art_title">
         <p>SWEET LIFE #1</p>
     </div>
     <div class="mask"></div>
</div>

所以,通过html重复它我显示了所有的图像,但现在我将它整合到wordpress中,我有以下问题:

我正在使用转发器字段来获取所有图像,所以使用以下代码:

<?php  $slides = get_field('project_thumbnails');  
        // Grabs the array      
       // Check if there is any data in the array before looping
         if($slides) {     
            //we need to close this div
           echo '<div id="project_slider" class="item">';     
           foreach($slides as $s) {  
                  echo '<div class="aimagediv" >'; //adding the start tag of the div
                  echo '<a href="#">';          
                  echo '<img src="'.$s['project_thumb'].'" alt="" />';
                  echo '</a>';
                  echo '</div>'; //CLOSING THE DIV JUST ADDED     
                 }        
                  echo '<div class="art_title">';        
                  echo '<p>SWEET LIFE2</p>';        
                  echo '</div>';        
                  echo '<div class="mask">';        
                  echo '</div>';  

                  echo '</div>'; //closing the first div,not sure if you want this, its optional
             }  

?>  <?php endwhile; // end of the loop. ?> 

我得到了转发器的图像,但是它显示在同一个div中,它没有创建一个新的div id =“项目”。所以它显示如下:

在页面上创建的标记就像所有图像都在同一个div中一样。

<div id="project" class="item">
     <a href="#">
        <img src="img/project1.jpg" alt="project1" width="240" height="173">
        <img src="img/project1.jpg" alt="project1" width="240" height="173">
     </a>
     <div class="art_title">
         <p>SWEET LIFE #1</p>
     </div>
     <div class="mask"></div>
</div>

我做错了什么?

1 个答案:

答案 0 :(得分:1)

<?php  $slides = get_field('project_thumbnails');  
        // Grabs the array      
       // Check if there is any data in the array before looping
         if($slides) {     
            //we need to close this div
           foreach($slides as $s) {  
                  echo '<div id="project_slider" class="item">';     
                  echo '<div class="aimagediv" >'; //adding the start tag of the div
                  echo '<a href="#">';          
                  echo '<img src="'.$s['project_thumb'].'" alt="" />';
                  echo '</a>';
                  echo '</div>'; //CLOSING THE DIV JUST ADDED     
                  echo '<div class="art_title">';        
                  echo '<p>SWEET LIFE2</p>';        
                  echo '</div>';        
                  echo '<div class="mask">';        
                  echo '</div>';  
                  echo '</div>'; //closing the first div,not sure if you want this, its optional
                 }
             }  

?>  <?php endwhile; // end of the loop. ?>