可以随机循环而不重复输入吗?
这是我的代码,但在第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">
答案 0 :(得分:2)
的functions.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;
}