Ashley Cameron Design

Ashley Cameron Design

Show Random Posts

SnippetsWordPress

About a 1 minute read

"This is the real secret of life — to be completely engaged with what you are doing in the here and now. And instead of calling it work, realize it is play."

Alan Watts


1
2
3
4
5
6
7
8
9
10
11
<?php //show random posts
    function randomPosts($numPosts = 5){
        query_posts(array('orderby' => 'rand', 'showposts' => $numPosts)); ?>
        <ul>
          <?php if (have_posts()) : while (have_posts()) : the_post(); ?>
            <li><a title="Permanent Link to <?php the_title(); ?>" href="<?php the_permalink(); ?>"><?php the_title(); ?></a></li>
            <?php endwhile; ?>
        </ul>
        <?php endif;
    wp_reset_query();
    } ?>