WordPress.org

Ready to get started?Download WordPress

Forums

Random posts in archive.php? (4 posts)

  1. Pete
    Member
    Posted 1 year 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 1 year 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. Pete
    Member
    Posted 1 year ago #

    Thanks i'll give it a go.

  4. Pete
    Member
    Posted 1 year 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