Well I can’t figure this one out…
I have this WordPress I use as a photo gallery blog.
I have a basic setup using the main default loop for posts.
Like this:
<?php if (have_posts()) : while (have_posts()) : the_post(); ?>
//the post
<?php endwhile; ?>
<b>Not Found</b>
<?php endif; ?>
In the sidebar and where ever, I want to appear random posts.
I’ve managed to do that. With this:
<?php query_posts($query_string . 'showposts=1&orderby=rand'); ?>
<?php if (have_posts()) : while (have_posts()) : the_post(); ?>
//the post
<?php endwhile; endif; ?>
It looks amazing! In theory.
There are duplicate posts all over the place. And that just looks stupid.
I have read lots of articles but I just can’t seem to get it to work 🙁
Any help would be much appreciated.
After a good night of sleep, here’s what I have done:
Creating array with post ID:
The Main loop where at the end I record the post ID to array:
And the random post code using post__not_in to avoid duplicates and again recording post ID:
Works evertime!
You can do amazing stuff with this 🙂
Thanks to paislee and Arvind Pal for helping out.