• 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

Viewing 3 replies - 1 through 3 (of 3 total)
  • <?php
    $args=array(
      '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>
        <?php
      endwhile;
    }
    wp_reset_query();  // Restore global post data stomped by the_post().
    ?>
    Thread Starter Jakub Machala

    (@machi)

    Wow, you rock! Thanks a lot…

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

Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘Display a list of random pages (without plugin, widget)’ is closed to new replies.