WordPress.org

Forums

Random posts in archive.php? (4 posts)

  1. Please Add Screenshots
    Member
    Posted 2 years ago #

    I've got this in my archive.php... but how do i randomise the posts?

    <?php if (have_posts()) : while (have_posts()) : the_post(); ?>
    <?php the_title();?>
    <?php endwhile; else: ?>

    Thanks heaps!!

  2. vtxyzzy
    Member
    Posted 2 years ago #

    Try changing this:

    <?php if (have_posts()) : while (have_posts()) : the_post(); ?>

    to this:

    <?php global $query_string;
    query_posts($query_string . '&orderby=rand');
    if (have_posts()) : while (have_posts()) : the_post(); ?>

    You should note that randomizing will interfere with pagination. Pagination really doesn't make sense with random retrieval.

  3. Please Add Screenshots
    Member
    Posted 2 years ago #

    Thanks i'll give it a go.

  4. Please Add Screenshots
    Member
    Posted 2 years ago #

    This worked

    <?php $posts = query_posts($query_string . '&orderby=rand'); ?>
    <?php if (have_posts()) : while (have_posts()) : the_post(); ?>

Topic Closed

This topic has been closed to new replies.

About this Topic