Skip to content

Instantly share code, notes, and snippets.

@dougedgington
Created March 20, 2013 08:21
Show Gist options
  • Save dougedgington/5203130 to your computer and use it in GitHub Desktop.
Save dougedgington/5203130 to your computer and use it in GitHub Desktop.
<?php
/*
Author: Doug Edgington
Description: Shortcode to output recent posts from one category
*/
function dee_display_recent_posts() {
$args = array(
'post_type' => 'post',
'posts_per_page'=> 5,
'cat'=> 4,
);
$dee_recent_posts = new WP_Query( $args );
if( $dee_recent_posts->have_posts() ):
$dee_output = '<ul>';
while ( $dee_recent_posts->have_posts() ) : $dee_recent_posts->the_post();
$dee_output .= '<li><a href="' . get_permalink() . '" title="' . get_the_title() . '">' . get_the_title() . '</a></li>';
endwhile;
$dee_output .= '</ul>';
endif;
return $dee_output;
wp_reset_postdata();
}
add_shortcode( 'recent-posts', 'dee_display_recent_posts' );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment