Multimedia and Web Design Firm
Flash replacement

Excluding current post / url in WordPress Loop

A 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.

One Response to “Excluding current post / url in WordPress Loop”

  1. Daniel Says:

    Hi there,

    Great post.

    I wonder if you could show me how i would need to add this into my loop?

    Been trying to find the answer for this for ages!

Leave a Reply

Telephone:

+44 (0)1224 582948

Office Address:

60 Nelson Street,
Aberdeen,
Scotland,
AB24 5ES