• Resolved johneemac

    (@johneemac)


    Hi there,

    I’m listing all the posts, in the loop, on a single post page. How can i exclude the current post’s url from the loop?

    I dont see the point in having a link to the post that is the current post web page.

    Iv done a lot of searching and amazed that there arn’t more questions about this.

    If anyone can help it would be very much appreciated.

    Thanks in advance. John.

Viewing 2 replies - 1 through 2 (of 2 total)
  • Assign the current post id to a vaiable, then in your loop that’s showing other posts test for and skip that post (or use the query_posts() post__not_in arguement).

    As a note, printing many posts on a single post page is a bit different ??

    If you continue this thread, paste your code in a pastebin such as wordpress.pastebin.ca and report the link back here.

    Thread Starter johneemac

    (@johneemac)

    Thanks for the reply. I used this code and its working.

    <?php query_posts(array('showposts'=> 6,'post__not_in' => array($post->ID))); ?>
      <?php while (have_posts()) : the_post(); ?>
          <li><a href="<?php the_permalink(); ?>"><?php the_title(); ?></a></li>
      <?php endwhile;?>
Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘Listing posts in the loop and EXCLUDING current post’ is closed to new replies.