分类
Wordpress

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(); } ?>

 

发表回复

您的邮箱地址不会被公开。 必填项已用 * 标注


RECOMMENDED