2012-11-19 151 views
0

我有一個畫廊,應該顯示3列,前兩列有一定的類,工作絕對好,但我想添加一個「最後一課」到我的第三列 - 出於某種原因,它是不工作。找到我的代碼如下:Wordpress last class not working

 <?php 

     $mod =1; 
     if ($images = get_posts(array(
      'post_parent' => $post->ID, 
      'post_type' => 'attachment', 
      'numberposts' => -1, 
      'post_mime_type' => 'image',))) 

     { 

     foreach($images as $image) { 

     $attachmenturl=wp_get_attachment_url($image->ID); 
     $attachmentimage=wp_get_attachment_image_src($image->ID, full); 
     $imageDescription = apply_filters('the_description' , $image->post_content); 
     $imageTitle = apply_filters('the_title' , $image->post_title); 
      if ($mod % 3 == 0) { 
      $class = "gallery-entry-img-last"; 
      }else{ 
      $class = "gallery-entry-img"; 
      } 
     echo '<div class="'.$class.'"><div class="gallery-entry-img-l"><a rel="next" href="' . $attachmentimage[0] . '"><span class="rollover" ></span><img src="library/tools/timthumb.php?src=' . $attachmentimage[0] . '&amp;w=270&amp;h=198" alt="" /></div></div>'; 
     } 
     $mod++; 
     }  
     else { 
      echo "No Image"; 
     } 



     ?> 

一些專家建議將不勝感激。

+0

難道是打印錯誤的類,或者它打印什麼? –

+0

謝謝您的回覆,它將以「gallery-entry-img」而不是「gallery-entry-img-last」的形式打印出來。 –

回答

3

增量您$mod變量中的foreach循環,如:

foreach(.....) { 
...... 
$mod++; 
} 
+0

的確 - 這確實有竅門!非常感謝Sudhir –

+1

不客氣...... :) –