2012-08-05 90 views
1

我在主索引頁上列出了4個圖像作爲小型投資組合展示,每個div類都具有「margin-right」屬性,因此我會找到一種方法來添加「last類「來刪除該特定屬性。wordpress爲特定圖片添加「last class」

我目前使用的代碼如下:

<div id="latestlistings" > 
    <div class="inner"> 
     <?php $recent = new WP_Query('post_type=listing&post_status=publish&posts_per_page='.get_option('wp_recentlistingsnumber_home')); ?> 
     <h3><?php echo get_option('wp_heading_recentlistings') ?></h3> 
     <?php if ($recent->have_posts()) : while ($recent->have_posts()) : $recent->the_post(); ?> 
     <?php include 'includes/variables.php' ?> 
     <div class="latestlisting"> 
     <?php $sliderimages = get_post_meta($post->ID, 'images_value', true); 
     if ($sliderimages) { 
      $arr_sliderimages = explode("\n", $sliderimages); 
      } else { 
      $arr_sliderimages = get_gallery_images(); 
      } 
      $firstimage = $arr_sliderimages[0]; 
      $arr_sliderimages = parse_url($firstimage); 

      $resized = timthumb(100, 200, $arr_sliderimages[path], 1); 
     ?> 
     <a href="<?php the_permalink(); ?>"><img width="200" height="100" src="<?php echo $resized ?>" /></a> 
     <div class="shadow-small"></div> 

    </div> 
</div> 

沒有任何人有一個想法或建議,如何讓這個最好的方式實現?一些建議將不勝感激 - 非常感謝你!

回答

2

您可以使用:last選擇或eq()方法,請嘗試以下操作:

$(document).ready(function(){ 
    $('.latestlisting:last').addClass('last'); 
    // or $('.latestlisting').eq(3).addClass('last'); 
}) 
+0

真是一個很好的解決方案Raminson - 非常感謝你,作爲作品的魅力! – 2012-08-05 03:08:10

+1

@PatrickLanfranco歡迎您:) – undefined 2012-08-05 03:12:45

相關問題