1

没有重复条目的随机循环是可能的吗?

这是我的代码,但在第 2 页,重复第 1 页的帖子。

<?php global $query_string;

query_posts( $query_string . '&orderby=rand' ); ?>

<?php while(have_posts()): the_post(); ?>

    <div id="post-<?php the_ID(); ?>" <?php post_class(); ?>>

            <div class="post-content">
4

1 回答 1

2

来自https://wordpress.stackexchange.com/questions/31647/is-it-possible-to-paginate-posts-correctly-that-are-random-ordered的解决方案

函数.php

session_start();

add_filter('posts_orderby', 'edit_posts_orderby');

function edit_posts_orderby($orderby_statement) {

    $seed = $_SESSION['seed'];
    if (empty($seed)) {
      $seed = rand();
      $_SESSION['seed'] = $seed;
    }

    $orderby_statement = 'RAND('.$seed.')';
    return $orderby_statement;
}
于 2013-09-30T19:52:22.633 回答