如何在WordPress中显示随机摘录?

时间:2014-09-08 14:18:07

标签: php arrays wordpress

早上好,我一直试图在帖子上摘录一个帖子,在主页上随机显示摘录,没有运气。我的代码如下所示:

    <?php
        $spotlight  = new WP_Query( array( 'post_type' => 'success-spotlight', 'posts_per_page' => 1,       'orderby' => 'rand' ) );
while ( $spotlight->have_posts() ) : $spotlight->the_post();
    $spotlight_title = get_the_title();
    $spotlight_excerpt = types_render_field("story-headline", array("raw"=>"true"));
    $spotlight_link = get_permalink();
    if (has_post_thumbnail()) {
        $thumb = wp_get_attachment_image_src(get_post_thumbnail_id(), 'spiffy-success-spotlight-`home');
        $spotlight_image = $thumb[0]; // thumbnail url
    }


endwhile; 
wp_reset_postdata();
?>
<?php

?>

任何建议都将不胜感激,并提前感谢您

1 个答案:

答案 0 :(得分:0)

怎么样:

query_posts('orderby=rand&showposts=1&post_type=success-spotlight');