Skip to content

Instantly share code, notes, and snippets.

@Dianakc
Created June 13, 2014 15:16
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Dianakc/6014d4f475218cfcf09e to your computer and use it in GitHub Desktop.
Save Dianakc/6014d4f475218cfcf09e to your computer and use it in GitHub Desktop.
Shortcode posts recente
<?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