在wordpress中随机选择一篇文章

在wordpress中随机选择一篇文章,wordpress,random,Wordpress,Random,我想在wordpress中制作一个插件,比如测验,但不是特殊问题。只有贴了。我将得到4个帖子标题和一个特色图片之间的这4个职位。客人将选择合适的特色图片标题。我收到随机的帖子 <ul> <?php $posts = get_posts('orderby=rand&numberposts=4'); foreach($posts as $post) { ?> <li><p desc="<?php the_permalink(); ?>"

我想在wordpress中制作一个插件,比如测验,但不是特殊问题。只有贴了。我将得到4个帖子标题和一个特色图片之间的这4个职位。客人将选择合适的特色图片标题。我收到随机的帖子

<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>
    • <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 
      ?>