wordpress add “last class” for specific images

I have 4 images listed on my main index page as small portfolio showcase, each div class features a “margin-right” attribute, I would therefore find a way to add a “last class” to have that specific attribute removed.

The code I currently use is as follow:

Read More
<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>

Does anybody have an idea or suggestion how to have this achieved in the best way? Some advise would be highly appreciated – thank you very much!

Related posts

Leave a Reply

1 comment

  1. You can use :last selector or eq() method, try the following:

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