分类
WordPress 用wp_query函数调用随机文章的方法
WordPress 用wp_query函数调用随机文章的方法
<?php
$args = array(
'post_type' => 'post',
'showposts' => 4,
'orderby' => 'rand',
'cat' => -36,//除了id为36的分类
);
$my_query = new WP_Query($args);
if( $my_query->have_posts() ) {
while ($my_query->have_posts()) : $my_query->the_post(); ?>
<div class="item">
<a href="<?php the_permalink(); ?>" class="box">
<?php the_post_thumbnail( array(285,360) ); ?>
<div class="text">
<strong><?php the_title();?></strong>
</div>
</a>
</div>
<?php endwhile; wp_reset_query(); } ?>