简体   繁体   中英

Wordpress random post code only show post from one author

I have a piece of code to show a random post under a post. But this code only show me the post's write from the author of that post. Whats wrong?

    <?php $posts = get_posts('orderby=rand&numberposts=3'); foreach($posts as $post) { ?>
        <div class="col-sm-12 col-md-6 col-xs-12 col-lg-4">
            <div class="thumbnail">
                <article>
                    <a href="<?php the_permalink();?>"><?php the_post_thumbnail('photo-thumbnail') ?></a>
                    <div class="caption">
                        <a href="<?php the_permalink();?>">
                            <h3 style="font-weight:bold; margin-top: 0px; line-height: 1.3;"><?php the_title(); ?></h3>
                        </a>
                    </div>
                </article>
            </div>
            <div class="thumbnailFooter">
                <div class="pull-left" style="margin-bottom: 4px;"><?php echo get_avatar( get_the_author_meta( 'ID' ), 32 ); ?></div>
                <div class="smallFont pull-left" style="margin-left: 5px; width: 240px;"><span class="blue bold"><?php the_author(); ?></span></div>
                <div class="verySmallFont pull-left" style="margin-left: 5px; margin-top: -3px;">en <span class="bold gray"><?php the_category(none); ?></span> el <?php the_time('j F, Y'); ?> </div>
            </div>
        </div>
        <?php } ?>

I'll ask again my answer with more data on other post

Can't reset query to show ramdom post after firs loop Wordpress

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM