WordPress Shortcode to Display the Loop

Just paste this into your theme’s function file.

"query" => '',
"category" => '',
), $atts));
global $wp_query,$paged,$post;
$temp = $wp_query;
$wp_query= null;
$wp_query = new WP_Query();
if($pagination == 'true'){
$query .= '&paged='.$paged;
$query .= '&category_name='.$category;
$query .= $query;

    have_posts()) : $wp_query->the_post(); ?>

Once your functions.php file is saved, you can display a loop :

[loop category="news" query="" pagination="false"]

Note that this code have been created to been used in pages. It have some oddity when used in a post.

Thanks to John Turner for this great piece of code!

Leave a Reply