Exclude Current Post from Query
I have a loop at the bottom of the page that cycles through randomly grabbing more posts from that category and displaying them as thumbnails. I’m able to get it work fine, but I can’t figure out how to exclude the current post that is being displayed. Here’s my code
$cat_ID = get_the_category($post->ID);
$cat_ID = $cat_ID->cat_ID;
<?php while (have_posts()) : the_post(); ?>
<div id="categoriesThumb" onclick="location.href='<?php the_permalink(); ?>';" style="cursor: pointer;">
<?php if ( has_post_thumbnail()) : ?>
" title="<?php the_title_attribute(); ?>" >
<?php the_post_thumbnail(array(85,58)); ?>
<?php endif; ?>
<?php the_title(); ?>
<?php endwhile; ?>
I’ve tried various ways to get it to exclude that post, but I can’t seem to figure it out. Any suggestions?
- The topic ‘Exclude Current Post from Query’ is closed to new replies.