Created
February 24, 2012 20:41
-
-
Save JLeuze/1903613 to your computer and use it in GitHub Desktop.
Simple plugin for random posts shortcode
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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