Forums

[resolved] Random post from database (3 posts)

  1. henkmsncam
    Member
    Posted 3 years ago #

    Hi,

    I searched a lot but I cant seem to find the right solution. What I would like is to show complete random full posts to each visitor from my database. Not only the title (I did see plugins for that)

    I am using the following code right now (in index.php)

    <?php if (have_posts()) : while (have_posts()) : the_post(); ?>
    <div class="entry">
    <h1 id="post-<?php the_ID(); ?>">" rel="bookmark"><?php the_title(); ?></h1>
    <div align="left"><?php the_content('Read the rest of this entry »'); ?></div>
    <div class="info">
    <p class="infoleft"><?php if ( the_tags('Tagged with ', ', ') ) ?></p>
    <p class="inforight"> <?php edit_post_link('Edit'); ?></p>
    <br clear="all" />
    </div>
    <?php if ( comments_open() ) comments_template(); ?>
    </div>
    <?php endwhile; else: ?>
    <div class="entry">
    <p><b>Sorry, but you are looking for something that isn't here.</b></p>
    </div>
    <?php endif; ?>

    thanks!

  2. MichaelH
    Volunteer
    Posted 3 years ago #

    Look at the orderby=rand parameter in the template tag, query_posts().

  3. henkmsncam
    Member
    Posted 3 years ago #

    Great thx. I added

    <?php
    if (is_home()) {
    query_posts('orderby=rand');
    }
    ?>

    before the loop and it works!

Topic Closed

This topic has been closed to new replies.

About this Topic