Created
April 23, 2015 07:42
-
-
Save AbhishekGhosh/de9b86c61b4bfce2448d to your computer and use it in GitHub Desktop.
Recent Posts WordPress PHP
This file contains hidden or 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 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