我在分类学归档(艺术家)中使用基本的循环代码,我想知道如何设置循环以随机顺序显示帖子('orderby'=
<?php
// Start the Loop.
while ( have_posts() ) : the_post();
/*
* Include the post format-specific template for the content. If you want to
* use this in a child theme, then include a file called called content-___.php
* (where ___ is the post format) and that will be used instead.
*/
array ( 'orderby' => 'RAND' );
get_template_part( 'content', get_post_format() );
endwhile;
// Previous/next page navigation.
twentyfourteen_paging_nav();
else :
// If no content, include the "No posts found" template.
get_template_part( 'content', 'none' );
endif;
?>
<?php
$query = new WP_Query( array ( 'orderby' => 'rand', 'posts_per_page' => '-1' ) );
if( $query->have_posts() ):
// Start the Loop.
while ( $query->have_posts() ) : $query->the_post();
/*
* Include the post format-specific template for the content. If you want to
* use this in a child theme, then include a file called called content-___.php
* (where ___ is the post format) and that will be used instead.
*/
get_template_part( 'content', get_post_format() );
endwhile;
// Previous/next page navigation.
twentyfourteen_paging_nav();
else :
// If no content, include the "No posts found" template.
get_template_part( 'content', 'none' );
endif;
?>
查询更多信息
query_posts数组
先问个好问题!
您可以使用PHP的简单函数来实现这一点。http://www.php.net/manual/en/function.shuffle.php
遵循以下步骤:
如有疑问,请在实施后问我。
谢谢