Excluding current post / url in Wordpress Loop
May 30th, 2009A very quick post today but hopefully this will help a few people.
Wordpress is a great tool for a small website requiring regular editing. While using the loop i wanted to find a way to exclude the current pages url from a list of links. There is no point in a page linking to itself!
By using the the post__not_in function its easy to do.
<?php query_posts(array('showposts'=> 6,'post__not_in' => array($post->ID)));
while (have_posts()) : the_post(); ?>
<li><a href="<?php the_permalink(); ?>"><?php the_title(); ?></a></li>
<?php endwhile;?>
Did it work? Any problems? Post a comment below.
