Created
June 13, 2014 15:16
-
-
Save Dianakc/6014d4f475218cfcf09e to your computer and use it in GitHub Desktop.
Shortcode posts recente
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 | |
function my_recent_posts_shortcode( $atts ) { | |
extract( shortcode_atts( array( 'limit' => 5 ), $atts ) ); | |
$q = new WP_Query( 'posts_per_page=' . $limit ); | |
$list = '<ul class="recent-posts">'; | |
while ( $q->have_posts() ) { | |
$q->the_post(); | |
$list .= '<li>' . get_the_date() . '<a href="' . get_permalink() . '">' . get_the_title() . '</a>' . '</li>'; | |
} | |
wp_reset_query(); | |
return $list . '</ul>'; | |
} | |
add_shortcode( 'recent-posts', 'my_recent_posts_shortcode' ); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment