现在,我的网站在我的单页文章末尾随机显示了3篇帖子。下面是我使用的代码,它可以工作(带有注释):
<?php
$rand_posts = get_posts(\'numberposts=3&orderby=rand&post_type=any&cat=-15\');
/*
Alternative Expression: (include all post types, exclude catefory \'site\' in the following code we define the post types explicitly instead of \'any\'")
$args = array(
\'orderby\' => \'rand\',
\'posts_per_page\' => 3,
\'category\' => -1,
\'post_type\' => array( \'post\', \'page\', \'oldp\' )
);
$rand_posts = get_posts( $args );
*/
foreach( $rand_posts as $post ) : ?>
我希望随机的帖子是我最好的帖子,也就是说,从我会选择或以某种方式确定的帖子池。如何做到这一点。我还有一个非常简单的随机引用代码,我想知道是否可以使用这样简单的代码来指定随机帖子池:
$quotes = array(
\'Quote1\',
\'Quote2\',
\'Quote3\',
);
return $quotes[rand(0, count($quotes)-1)];