Display a Random Post (6 posts)

  1. rush1
    Posted 7 years ago #

    I'd like to display a random article that is selected from every post I've made (in all categories).

    Is there some simple code to accomplish this?

  2. thisisedie
    Posted 7 years ago #

    Please remember that Google is your friend. I typed in wordpress + display random post and within seconds found the following


    There's many more to choose from if those don't suit you.

  3. @mercime
    Volunteer Moderator
    Posted 7 years ago #

    If you would like to hard code in template see Codex Random Posts

  4. trench
    Posted 6 years ago #

    I know this is an old post but it helped me out a lot. Thanks guys.

  5. @mercime
    Volunteer Moderator
    Posted 6 years ago #

    glad it helped.

  6. carl-johan
    Posted 6 years ago #

    Since this one's still a little active. I've used

     $rand_posts = get_posts('numberposts=5&orderby=rand');
     foreach( $rand_posts as $post ) :
        <li><a href="<?php the_permalink(); ?>"><?php the_title(); ?></a></li>
     <?php endforeach; ?>

    to get a rand post which works fine, as long as I choose to display the_title or the_excerpt (both, of course, text only). But if I choose the content, which are images, it doesn't display anything. Could someone give me a hint why images wont show?


Topic Closed

This topic has been closed to new replies.

About this Topic


No tags yet.