2012-01-30 43 views
0

我正在開發項目,我一直在試圖抓取隨機文章和帖子縮略圖,但是我的代碼並沒有像我認爲的那樣工作。每次運行此代碼時,我都會看到所有帖子的相同內容(但縮略圖圖像不同)。請幫助我解決此問題。在WordPress中獲得隨機文章(帶縮略圖)

<ul> 
    <?php $posts = get_posts('orderby=rand&numberposts=5'); foreach($posts as $post) : ?> 
    <li> 
     <div class="thumb-img"> 
      <?php if (has_post_thumbnail()) : ?> 
       <a href="<?php the_permalink(); ?>" title="<?php the_title_attribute(); ?>" > 
       <?php the_post_thumbnail(array(165,112)); ?> 
       </a> 
     </div> 
     <div class="post-text"> 
     <?php //the_excerpt(); ?> 
      <?php global $more; $more = 0; the_content('<span class="more">more</span>'); ?> 
      <?php endif; ?> 
     </div> 
    </li> 
    <?php endforeach; ?> 
    </ul> 
+0

plz guys helps me – Muzammil 2012-01-30 19:14:22

+0

永久鏈接每次都不一樣嗎? – Swadq 2012-01-30 19:51:19

回答

0

,如果你嘗試簡化您這樣的代碼,第一個是什麼:

<ul> 
<?php 
$posts = get_posts('orderby=rand&numberposts=5'); 
foreach($posts as $post) : 
?> 
<li> 
    <?php if (has_post_thumbnail()) : ?> 
    <div class="thumb-img"> 
     <a href="<?php the_permalink(); ?>" title="<?php the_title_attribute(); ?>" > 
     <?php the_post_thumbnail(array(165,112)); ?> 
     </a> 
    </div> 
    <?php endif; ?> 
    <div class="post-text"> 
     <?php the_excerpt(); ?> 
    </div> 
</li> 
<?php endforeach; ?> 
</ul> 

是否幫助呢?

相關問題