2012-01-30 42 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> 

是否帮助呢?

相关问题