WordPress.org

Ready to get started?Download WordPress

Forums

Display a Random Post (6 posts)

  1. rush1
    Member
    Posted 5 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
    Member
    Posted 5 years ago #

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

    http://www.romantika.name/v2/wordpress-plugin-random-posts-widget/
    http://www.bloganything.net/637/download-wordpress-plugin-random-post

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

  3. @mercime
    Volunteer Moderator
    Posted 5 years ago #

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

  4. trench
    Member
    Posted 5 years ago #

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

  5. @mercime
    Volunteer Moderator
    Posted 5 years ago #

    glad it helped.

  6. carl-johan
    Member
    Posted 5 years ago #

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

    <?php
     $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?

    Thanks!

Topic Closed

This topic has been closed to new replies.

About this Topic

Tags

No tags yet.