Skip to content

Instantly share code, notes, and snippets.

@JLeuze
Created February 24, 2012 20:41
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save JLeuze/1903613 to your computer and use it in GitHub Desktop.
Save JLeuze/1903613 to your computer and use it in GitHub Desktop.
Simple plugin for random posts shortcode
<?php /*
Plugin Name: JL Random Posts */
function jl_random_posts() {
$jlrandom_output = '';
$jlrandom_loop = new WP_Query( array( 'posts_per_page' => 3, 'orderby' => 'rand' ) );
while ( $jlrandom_loop->have_posts() ) : $jlrandom_loop->the_post();
$jlrandom_output .= '<li><a href="' . get_permalink() . '">' . the_title( '', '', false ) . '</a></li>';
endwhile;
wp_reset_query();
return '<ul>' . $jlrandom_output . '</ul>';
}
add_shortcode( 'jlrandom', 'jl_random_posts' ); ?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment