Created
March 20, 2013 08:21
-
-
Save dougedgington/5203130 to your computer and use it in GitHub Desktop.
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 | |
/* | |
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