Skip to content

Instantly share code, notes, and snippets.

@j0lvera
Last active December 12, 2015 07:29
Show Gist options
  • Save j0lvera/4737112 to your computer and use it in GitHub Desktop.
Save j0lvera/4737112 to your computer and use it in GitHub Desktop.
Recent Posts Shortcode
<?php
// Recent Posts
function recent_posts($atts){
$q = new WP_Query(
array( 'orderby' => 'date', 'posts_per_page' => '4')
);
$list = '<ul class="recent-posts">';
while($q->have_posts()) : $q->the_post();
$list .= '<li>' . get_the_post_thumbnail() . '<a href="' . get_permalink() . '">' . get_the_title() . '</a>' . '</li>';
endwhile;
wp_reset_query();
return $list . '</ul>';
}
add_shortcode('recent_posts', 'recent_posts');
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment