Randomizing posts without dupicating on next page? (8 posts)

  1. liberty50
    Posted 6 years ago #

    Hi folks,

    I am working on a theme that requires randomizing the order of the loop display in categories. This is the code that I am using, which works, but when I move to the next or previous page, duplicates are displayed.

    query_posts($query_string . '&orderby=rand');
    <?php if (have_posts()) : ?>
    <?php while (have_posts()) : the_post(); ?>

    I am hoping that someone here has worked through this same issue and might offer some advise.


  2. liberty50
    Posted 6 years ago #

    I'm bumping this question because all my efforts today have not resulted in an resolution. It seems as though the code I am currently using is querying random posts both on the first archive page and then again(a new query) on the previous-next page(s). Some posts are displayed twice, and others never at all. What I need is for the entire category to be queried, that list of post randomized, then displayed on the front page and following pages.

    Any advise would be great. This one has me totally baffled.

    Thanks again

  3. liberty50
    Posted 6 years ago #

    I am still trying to resolve this issue. Very frustrating.

    I've tried adding the orderby=rand parameter to the archive.php loop in every way I can find. So far nothing has worked quite right. I am bumping this post one last time in hopes that someone has experience with this issue.

    Thanks ahead of time!

  4. MichaelH
    Posted 6 years ago #

    Please paste all the code from the theme template files (probably index.php and category.php) that is displaying those posts into a pastebin, such as wordpress.pastebin.ca, and report the link(s) back here. Maybe someone might spot your problem. Thanks.

  5. MichaelH
    Posted 6 years ago #

    Also provide a link to see the problem and point out which are duplicate posts.

  6. liberty50
    Posted 6 years ago #

    I believe the issue is with my coding on the archive page, here is the link to that in a pastebin.

    The loop begins about halfway down the page.

    Thanks for looking!

  7. MichaelH
    Posted 6 years ago #

    not sure what this does:

    <?php include(TEMPLATEPATH."/sidebarhome.php");?>

    but your logic looks okay to me...

    Might try echo "<pre>"; print_r($wp_query); echo "</pre>"; before query to see if you see anything...don't have much else...sorry.

  8. liberty50
    Posted 6 years ago #

    Michael thanks for looking.

    I'll keep messing around with it, and try your suggestions.

Topic Closed

This topic has been closed to new replies.

About this Topic