Written in response to something John Cotton wrote.
John has got a point there.
ps: I was courious why the other solutions didn't work, so I found out why:
a) there was a tiny misspell in Keith Donegan's solution, there was a missing "t" in the $ouput variable name (should have been $output)
b) and I forgot to put $post->ID inside get_the_title(), but I don't like query_posts for various reasons so I used get_posts instead.
So here are the two corrected solutions just for referance:
Keith Donegan's solution
Dbrane's solution
ps: I was courious why the other solutions didn't work, so I found out why:
a) there was a tiny misspell in Keith Donegan's solution, there was a missing "t" in the $ouput variable name (should have been $output)
b) and I forgot to put $post->ID inside get_the_title(), but I don't like query_posts for various reasons so I used get_posts instead.
So here are the two corrected solutions just for referance:
Keith Donegan's solution
add_shortcode('random_quotes', 'my_random_quotes');
function my_random_quotes(){
$output = '';
//The Query
query_posts('post_type=client-quotes&posts_per_page=1&orderby=rand');
//The Loop
if ( have_posts() ) : while ( have_posts() ) : the_post();
$output .= '<h3>' . get_the_title() . '</h3>';
$output .= '<p class="name"><a title="Testimonials from our clients" href="/testimonials-from-our-clients/">...read more</a></p>';
endwhile; else:
endif;
//Reset Query
wp_reset_query();
return $output;
}
Dbrane's solution
//add_shortcode('random_quotes', 'my_random_quotes');
function my_random_quotes(){
$s="";
$posts=get_posts(array( 'post_type'=>'post','numberposts' =>2,'orderby'=>'rand'));
foreach( $posts as $post ){
setup_postdata($post);
$s.="<h3>".get_the_title($post->ID)."</h3>";
$s.='<p class="name"><a title="Testimonials from our clients" href="/testimonials-from-our-clients/">...read more</a></p>';
}
}
Updated: 11/08/12 7:34am


