2014-11-03 47 views
0

我想在wordpress中插入一個插件,但不包含特殊問題。只有帖子。我將在這4篇文章之間獲得4篇文章和1篇精選影像。客人將選擇精選圖像的正確標題。我得到隨機帖子;在wordpress中選擇一個隨機帖子

<ul> 
<?php $posts = get_posts('orderby=rand&numberposts=4'); foreach($posts as $post) { ?> 
<li><p desc="<?php the_permalink(); ?>" title="<?php the_title(); ?>"><?php the_title(); ?></p> 
</li> 
<?php } ?> 
</ul> 

但我無法解決我將如何隨機選擇正確的答案,並得到它的特色圖像作爲一個問題。

請幫助

回答

0
<ul> 
    <?php 
     $arr = array(); 
     $posts = get_posts('orderby=rand&numberposts=4'); 
     foreach($posts as $post) { ?> 
     <li> 
      <p desc="<?php the_permalink(); ?>" title="<?php the_title(); ?>"><?php the_title(); ?> </p> 
      <?php $arr[ get_the_ID() ]; // store every post id in array ?> 
     </li> 
    <?php } ?> 
</ul> 
<?php 
    $id = array_rand($arr); // choose one random post id 
    echo get_the_post_thumbnail($id,'thumbnail'); // get thubnail against id 
?> 

使用此代碼,並比較用戶選擇的帖子ID '$ id' 值。

乾杯!

相關問題