2013-09-30 28 views
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"> 
+1

您可以創建的數組在此query_posts期間檢索到的id值,並通過在您的query_string:array(1,2,3)中附加'post__not_in'=> array(1,2,3)將該數組傳遞給下一頁的query_posts將是arra y持有前一頁的id值......或分頁查詢初始結果 – zoranc

+0

uooh !!真的感謝。現在我明白了一些,但是你能幫我一個代碼示例或類似的東西嗎?感謝 – vektor

+1

種子的查詢和每個會話分頁結果,看看[這個](http://wordpress.stackexchange.com/questions/31647/is-it-possible-to-paginate-posts-correctly-that - 是隨機排序的)......他們在回答 – zoranc

回答

2

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

的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; 
} 
+0

我已經實現了這一點,但是是否有可能使它刷新更改?因爲這隻有在我清除我的Cookie和緩存時纔會發生變化。 – probablybest