Query a random post

Here’s a random post snippet I used on teh Better For Business website to feature a different Advisor on each page load.

<!--Call RANDOM POST:  ADVISORS-->
 <?php query_posts(array('orderby' => 'rand', 'category_name' => Advisors, 'showposts' => 1)); if (have_posts()) : while (have_posts()) : the_post(); ?><div>
 <h3><a href="<?php the_permalink() ?>" rel="bookmark">featured Advisor</a></h3>

 <?php    $values = get_post_custom_values("image");
 if (isset($values[0])) { ?>
 <a href="<?php the_permalink() ?>" rel="bookmark" title="Permanent Link to <?php the_title(); ?>">
 <img src="<?php echo bloginfo('template_url'); ?>/scripts/timthumb.php?src=wp-content/uploads/<?php $values = get_post_custom_values("image"); echo $values[0]; ?>&w=75&h=99&zc=1&q=100"
 alt="<?php the_title(); ?>" /></a>
 <?php } ?>

 <b><?php the_title(); ?></b><br/>
 <?php the_excerpt(); ?>

 <div>
 <a href="<?php the_permalink() ?>" rel="bookmark" title="Permanent Link to <?php the_title(); ?>">read more &raquo;</a>
 </div>
</div>
<?php endwhile; else: ?>

Revisions

There are no revisions for this post.

Tags: , ,

No comments yet.

Leave a Reply