widget - wordpress recent posts show thumbnail -
how can show either small thumbnail of image or featured image, each post in recent posts custom widget
here's code:
<?php include($_server['document_root'] . $root . 'blog/wp-load.php'); $recent_posts = wp_get_recent_posts(array( 'numberposts' => 3 )); ?> <h3 class="divider">recent blog posts</h3> <ul class="listing"> <?php foreach($recent_posts $post) { ?> <li><a href="<?php echo get_permalink($post['id']) ?>"> <div><?php echo $post['post_title'] ?></div></a></li> <?php } ?> </ul>
you can use get_the_post_thumbnail
usage:
<?php echo get_the_post_thumbnail( $post_id, $size, $attr ); ?>
integrated code:
<?php foreach($recent_posts $post) : ?> <li> <a href="<?php echo get_permalink($post['id']) ?>"> <?php echo get_the_post_thumbnail($post['id'], 'thumbnail'); ?> <div><?php echo $post['post_title'] ?></div> </a> </li> <?php endforeach; ?>
note: enable post thumbnails, current theme must include add_theme_support( 'post-thumbnails' );
in functions.php file. see post thumbnails.
source(s)
function reference/get post thumbnail
see also
Comments
Post a Comment