![]()
前几日在wpcourse分享了一篇关于wordpress随机文章的实现方式与进阶用法,现在重新整理在这里,以便留档。
wordpress实现随机文章
随机文章的实现方法,可以按照以下代码进行:
<?php
$query = array(
'post_type' => 'post',
'orderby' => 'rand'
);
$posts = new WP_Query( $query );
if ( $posts->have_posts() ) {
while( $posts->have_posts() ) :
$posts->the_post();
the_content();
endwhile;
}
wp_reset_query();
?>
格式和写法可以根据你个人的喜好,还可以写得更加简洁。
Continue reading wordpress随机文章