Last active
December 12, 2015 07:29
-
-
Save j0lvera/4737112 to your computer and use it in GitHub Desktop.
Recent Posts Shortcode
This file contains hidden or 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 | |
// 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