View Single Post
Old 11-05-2011, 09:17 AM  
vdbucks
Monger Cash
 
Industry Role:
Join Date: Jul 2010
Posts: 2,773
Here ya go.. the proper way to do it ><

For use as the main or only loop:
PHP Code:
<?php
$args1 
= array(
        
'posts_per_page'    => 5,
        
'orderby'        => 'rand',
        
'post_status'        => 'publish',
        
'offset'        => 0
    
);
query_posts($args1);

if (
have_posts()) : while (have_posts()) : the_post(); ?>
    <li>
    <h2><a href="<?php the_permalink(); ?>"><?php the_title(); ?></a></h2>
    <p><img src="<?php echo get_post_meta($post->IDthumbnailtrue); ?>" width="100" height="100"></p>
    </li>
<?php endwhile; endif; ?>
Use this as a secondary loop on a page with multiple loops... will save some resources by using the initial query from the main loop as opposed to creating a new query:
PHP Code:
<?php 
$args2 
= array(
        
'posts_per_page'    => 5,
        
'orderby'        => 'rand',
        
'post_status'        => 'publish',
        
'offset'        => 0
    
);
$rand_posts get_posts($args2);

foreach (
$rand_posts as $post) : setup_postdata($post); ?>
    <li>
    <h2><a href="<?php the_permalink(); ?>"><?php the_title(); ?></a></h2>
    <p><img src="<?php echo get_post_meta($post->IDthumbnailtrue); ?>" width="100" height="100"></p>
    </li>
<?php endforeach; ?>
vdbucks is offline   Share thread on Digg Share thread on Twitter Share thread on Reddit Share thread on Facebook Reply With Quote