Skip to content

Instantly share code, notes, and snippets.

@atsea
Created April 22, 2015 19:24
Show Gist options
  • Save atsea/c3a7ef9e2012a4a47a70 to your computer and use it in GitHub Desktop.
Save atsea/c3a7ef9e2012a4a47a70 to your computer and use it in GitHub Desktop.
wordpress - display thubmnail in sidebar recent posts
<?php
/**
* http://officetricks.com/display-recent-posts-with-thumbnails-without-plugins/
* Display Recent Posts with Thumbnails without Plugins – WordPress
*/
$recent_posts = wp_get_recent_posts();
foreach( $recent_posts as $recent ){
if($recent['post_status']=="publish"){
if ( has_post_thumbnail($recent["ID"])) {
echo '<li style="padding:5px;border-bottom:1px solid goldenrod;">
<a href="' . get_permalink($recent["ID"]) . '" title="Look '.esc_attr($recent["post_title"]).'" >' . get_the_post_thumbnail($recent["ID"], 'thumbnail'). $recent["post_title"].'</a></li> ';
}else{
echo '<li style="padding:5px;border-bottom:1px solid goldenrod;">
<a href="' . get_permalink($recent["ID"]) . '" title="Look '.esc_attr($recent["post_title"]).'" >' . $recent["post_title"].'</a></li> ';
}
}
}
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment