投稿をランダムに出力する
wordpressの投稿をランダムに出力します。
orderby=randで並び順をランダムにできます。orderbyは順序付けパラメータです。
post_type=worksでカスタム投稿タイプ”works”のみに絞っています。これをなくすと投稿すべてランダムにできます。
PHP
1 2 3 4 5 6 7 8 9 10 11 12 | <h3 class="navi_title">Other works</h3> <?php query_posts('showposts=3&orderby=rand&post_type=works'); ?> <!-- カスタム投稿タイプ"works"の記事をランダムに3件出力する --> <?php if(have_posts()): while(have_posts()):the_post(); ?> <div class="navi_inner"> <a href="<?php the_permalink(); ?>"><?php the_post_thumbnail('thumbnail'); ?> </a> </div> <?php endwhile; endif; ?> |