WordPress.org

Ready to get started?Download WordPress

Forums

[resolved] Rotate or Shuffle My Posts (4 posts)

  1. shawngoesgreen
    Member
    Posted 4 years ago #

    I have a site with my art portfolio. Each piece is a photo with a description. I would like to randomly have an older post come up to the first place on the home page. Is there a way to do this manually or with a plugin?

    The plugin "rotating posts" is not what I want it to do but it looks like a great plugin anyway.

  2. MichaelH
    Member
    Posted 4 years ago #

    This will retrieve and display one random post.

    <?php
    $args=array(
      'orderby' => 'rand',
      'post_type' => 'post',
      'post_status' => 'publish',
      'posts_per_page' => 1,
      'caller_get_posts'=> 1
    );
    $my_query = null;
    $my_query = new WP_Query($args);
    if( $my_query->have_posts() ) {
      echo 'List of Posts';
      while ($my_query->have_posts()) : $my_query->the_post(); ?>
        <p><a href="<?php the_permalink() ?>" rel="bookmark" title="Permanent Link to <?php the_title_attribute(); ?>"><?php the_title(); ?></a></p>
        <?php
        the_content();
      endwhile;
    }
    wp_reset_query();  // Restore global post data stomped by the_post().
    ?>

    Related:
    Stepping Into Template Tags
    Stepping Into Templates
    Template Hierarchy

  3. shawngoesgreen
    Member
    Posted 4 years ago #

    Thanks for the help Michael.

  4. newftronics
    Member
    Posted 3 years ago #

    My question is the same as shawngoesgreen however I do not know what to do with the Script that MichaelH has provided. I am a Newbee to WordPress so I am sure this question will seem to be easy to most. Any help would be greatly appreciated.

Topic Closed

This topic has been closed to new replies.

About this Topic