Ready to get started?Download WordPress


[resolved] Display a list of random pages (without plugin, widget) (4 posts)

  1. Machi
    Posted 4 years ago #

    Hi there,
    I was trying to find this simple thing but I didn't have any luck. So please...

    Is there a way how to display a random list of pages? I just need to specify a number of pages and the function returns a list of completely random pages (pages & subpages).

    Thanks a lot, Jakub

  2. MichaelH
    Posted 4 years ago #

      'orderby' => 'rand',
      'post_type' => 'page',
      'post_status' => 'publish',
      'posts_per_page' => 3,
      'caller_get_posts'=> 1
    $my_query = null;
    $my_query = new WP_Query($args);
    if( $my_query->have_posts() ) {
      echo 'List of 3 random pages';
      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>
    wp_reset_query();  // Restore global post data stomped by the_post().
  3. Machi
    Posted 4 years ago #

    Wow, you rock! Thanks a lot...

  4. Pete
    Posted 4 years ago #

    How would I exclude certain pages from this list? Thanks.

Topic Closed

This topic has been closed to new replies.

About this Topic