Skip to content

Instantly share code, notes, and snippets.

@rosshanney
Created January 6, 2013 20:27
Show Gist options
  • Save rosshanney/4470001 to your computer and use it in GitHub Desktop.
Save rosshanney/4470001 to your computer and use it in GitHub Desktop.
<?php
function my_recent_posts_shortcode( $atts ) {
extract( shortcode_atts( array( 'limit' => 5, 'categories' => '' ), $atts ) );
$q = new WP_Query( 'posts_per_page=' . $limit . '&category_name=' . $categories );
$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