WP_Query +随机


16

有什么办法可以做到这一点

<?php 
$pc = new WP_Query ('category_name=cat1&posts_per_page=5'); 
?> 

但每次显示RANDOM的5个批次都不一样吗?

Answers:


23

请尝试以下方法:

$args = array(
    'category_name'  => 'cat1',
    'posts_per_page' => 5,
    'orderby'        => 'rand',
);

$pc = new WP_Query( $args ); 

在哪里'rand'应该给您随机排列的帖子。

有关更多信息,请在此处查看有关订购参数的食典WP_Query

By using our site, you acknowledge that you have read and understand our Cookie Policy and Privacy Policy.
Licensed under cc by-sa 3.0 with attribution required.