今天,本文分享Wordpress输出随机文章的代码,不使用插件。
详细如下:

<div class="rnd_list"">
<ul style="list-style:none;">
<?php
$args = array( 'numberposts' => 6, 'orderby' => 'rand', 'post_status' => 'publish' );
$rand_posts = get_posts( $args );
foreach( $rand_posts as $post ) : ?>
    <li><a href="<?php the_permalink(); ?>"><?php the_title(); ?></a></li>
<?php endforeach; ?>
</ul>
</div>