Related post by category: {if id = to current page id} should not display in related post

I workout wordpress related post by category.
my problem is I don’t want to display the item in current post in the related post.

for example: i have list of item belong to color category which is red, blue, green, black and red is my current page, I don’t want red appear in Related post

<?php foreach((get_the_category()) as $category) {$id = $category->cat_ID;} ?>

     <ul class="recentWorks">
             <?php
            if (have_posts()) : {
            $paged = (get_query_var('paged')) ? get_query_var('paged') : 1;
            query_posts("&cat={echo $id;}&showposts=6&paged=$paged&order=ASC");
            }
            while(have_posts()) : the_post();
          ?>
          <li>
            <a class="imageHover" href="<?php the_permalink(); ?>" id="post-<?php the_ID(); ?>"><?php the_title(); ?></a>
            <?php if ( has_post_thumbnail()) the_post_thumbnail('post-thumbnails'); ?>
            <span><?php the_title(); ?></span>
          </li>
          <?php endwhile; ?>
         <?php endif; ?>
          </ul>

Read more here: Related post by category: {if id = to current page id} should not display in related post

Leave a Reply

Your email address will not be published. Required fields are marked *