2011-11-21 189 views
0

我在一個網站上工作是一個客戶端想要顯示一個隨機的證書,刷新時旋轉。正在使用的推薦僅僅是人們留下的評論。所以,我非常喜歡拉動評論摘錄,但我無法得到它隨機評論,它只是拉最新的。有沒有辦法做到這一點?這是我正在使用的代碼:WordPress的評論

<?php 

     $args = array(
     'status' => approve, 
     'number' => 1, 
     'orderby' => 'rand', 
     ); 

     $comments = get_comments($args); ?> 
     <h3 class="side-heading">Customer Tesimonials</h3> 
      <div class="testimonials-inner"> 
       <div class="testimonials-inner-inner"> 
       <?php foreach ($comments as $comment) { ?> 
        <p><?php 
         $title = get_the_title($comment->comment_post_ID); 
         echo get_avatar($comment, '53'); 
         //echo '<span class="recommauth">' . ($comment->comment_author) . '</span>'; 
         ?>"<?php 
         echo wp_html_excerpt($comment->comment_content, 72); ?>" 
        </p> 
       <?php } ?> 

       <br /> 

       <a class="re" href="/"><h4 class="butt-sub">Tell Your Story</h4></a> 
       </div> 
      </div> 
     </div> 
    </div> 

謝謝!

+0

乍一看,代碼看起來很好。嘗試禁用插件。已知WP Sticky會導致問題。 –

+0

http://codex.wordpress.org/Function_Reference/get_comments - 「order」的有效值僅爲「ASC」和「DESC」。 – artlung

回答

0

這不是測試的代碼,但這樣的事情?

<?php 
    $args = array(
     'status' => 'approve', 
    ); 

    $all_comments = get_comments($args); 
    $random_key = array_rand($all_comments, 1); 

    $comments = array($all_comments[$random_key]); ?> 
+0

我試過但沒有工作。感謝您的幫助! –