wordpress添加“;最后一类“;用于特定图像


wordpress add "last class" for specific images

我在我的主索引页面上列出了4个图像作为小型投资组合展示,每个div类都有一个"margin-right"属性,因此我会想办法添加一个"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>

有人对如何以最佳方式实现这一目标有想法或建议吗?非常感谢您的建议,非常感谢!

您可以使用:last选择器或eq()方法,尝试以下操作:

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