WordPress.org

Ready to get started?Download WordPress

Forums

Create a page that has a random post in it? (4 posts)

  1. neodan
    Member
    Posted 4 years ago #

    How do I do this? I want a whole new page that will display a random post.

    Is there a plugin of the sort?

  2. gerbilk
    Member
    Posted 4 years ago #

    <?php
    
    //The Query
    
    query_posts('showposts=1&orderby=rand');
    
    if ( have_posts() ) : while ( have_posts() ) : the_post();
    
    endwhile; else:
    
    endif;
    
    //Reset Query
    wp_reset_query();
    
    ?>
  3. neodan
    Member
    Posted 4 years ago #

    Thanks. However that looks like a foreign language to me.

    Where do I put that code? Do I create a page and put it in the HTML view?

  4. gerbilk
    Member
    Posted 4 years ago #

    you need to edit the theme template, probably the page.php file, you'll also need to set up a custom page template. Just google these terms, it sounds complicated but it's really quite easy.

Topic Closed

This topic has been closed to new replies.

About this Topic

Tags

No tags yet.