<?php global $wpdb; $attachment_id = $wpdb->get_var("SELECT ID FROM $wpdb->posts WHERE post_parent = '$post->ID' AND post_status = 'inherit' AND post_type='attachment' ORDER BY post_date DESC LIMIT 1"); $tip = wp_get_attachment_url($post->ID); if ( have_posts() ) : while ( have_posts() ) : the_post(); ?> <div class="screenimg"> <a href="<?php the_permalink() ?>" rel="<?php echo wp_get_attachment_url($attachment_id); ?>" class="tip"><?php the_post_thumbnail(array(330, 190)); ?></a> </div> <?php endwhile; ?> <?php endif; ?>