Well let’s see what you’re using to grab said posts first… 😉
You can add the current post ID as an exclude to whatever code you’re using.. exclude is supported in both query_posts and get_posts , and i’d assume you’re using one of those..
thanks and here you go
if ( in_category(‘373’) ):
$recent = new WP_Query(“cat=373&showposts=3&orderby=rand”); while($recent->have_posts()) : $recent->the_post();
title
endwhile;
else
endif
I’ve tried this
http://weblogtoolscollection.com/archives/2008/05/17/how-to-avoid-duplicate-posts/
but it didnt work.
I tried another one which uses some array thingy but and it worked but however it did not really exclude but merely print nothing so my 3 random posts becomes 2. The thing is I’m displaying pictures in static position so when it’s done that way, the space is blank which isn’t what i want.
So what i want is to really exclude it while they search for posts randomly…and give me 3 posts that is not the current post…
http://wordpress.org/support/topic/206936?replies=2
This was what I used but it turned out one misses instead of excluding…..
Something as simple as..
$currentID = get_the_ID();
$recent = new WP_Query( 'exclude=' . $currentID . '&cat=373&showposts=3&orderby=rand' );
Should do the trick..
hmmm Didn’t work…….anything else I need to add to capture the ID? Or it’ll just GET-THE-ID?
Can i see the complete code for the file you’re using this in?
Plonk the code in a pastebin.
http://wordpress.pastebin.com/
http://wordpress.pastebin.com/d24ed2c43
Maybe you’ll like to know how do I know it didn’t work.
Because the category I test out on has only 4 posts and when I gone test one of those post, it still display 4 related posts which also include that current posts.
<?php
$yourcat = 373; // Stick the ID here and it'll be placed in the relevant places below.
if( in_category( $yourcat ) ) :
$my_query = new WP_Query(array(
'showposts' => 3,
'orderby' => 'rand',
'cat' => $yourcat,
'post__not_in' => array($post->ID)
)); unset($yourcat);
while ($my_query->have_posts()) : $my_query->the_post();
?>
<a href="<?php the_permalink(); ?>"><img src="<?php echo p75GetThumbnail($post->ID, 100, 100); ?>"></a>
<?php
endwhile;
endif;
?>
Took a little while to figure why it wouldn’t work…. just needed to use an array with the posts__not_in parameter…
Above is tested as working….
Yes!!!!! Lovely!!!! Thanks!!!