检测具有相同背景图像值的元素并移除


Detect elements with same background-image value and remove

我正在显示一个帖子的提要,其中一些使用相同的背景图像。我想找到并隐藏重复的文件。

完整代码:

 <?php 
    $args=array(
                'cat' => '1',
                'post_status' => 'publish',
                'post_type' => 'post',
                'posts_per_page' => 10,
                'taxonomy' => 'postkicker',
                'term' => 'vote',
                'orderby'    => 'date',
                'order'      => 'DESC'
    );
    $my_query = new WP_Query($args);
    if ( $my_query->have_posts() ) : 
    while ( $my_query->have_posts() ) : $my_query->the_post();  
   $src = wp_get_attachment_image_src( get_post_thumbnail_id($post->ID),  array( 284,110 ), false, ''  );
 ?>
    <div class="divider-left">
     <a class="img-thumbnew" href="<?php the_permalink(); ?>" title="<?php the_title_attribute(); ?>">
     <div style="background-image: url(<?php echo $src[0]; ?> );"></div>
     </a>
     </div>

我没有看到循环在哪里发生。但是穷人的答案是跟踪在循环中看到的src,然后在找到

时中止。
<?php
   $srcs_seen = array();
   while ( // looping over stuff ) {
       $src = wp_get_attachment_image_src(
           get_post_thumbnail_id($post->ID),  array( 284,110 ), false, ''  
       );
       // keep looping but stop here if we've seen it
       if (in_array($src['url'], $srcs_seen)) continue; 
       $srcs_seen[] = $src['url'];
       // print html like you were doing
   }
?>