最新投稿10件の中からランダム5件表示
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 |
<?php $args = array( 'posts_per_page' => 10 ); $posts_array = get_posts( $args ); foreach ( $posts_array as $post ) : setup_postdata( $post ); $post_id = $post->ID; $id_array[] = $post->ID; endforeach; wp_reset_postdata(); $args = array( 'post__in' => $id_array, 'orderby' => 'rand', 'posts_per_page' => '5', ); $query = new WP_Query( $args ); while ( $query->have_posts() ) { $query->the_post(); echo '<p>' . get_the_title() . '</p>'; } wp_reset_postdata(); ?> |
コメント