Support » Plugins and Hacks » [Resolved] Can I call 5 recent posts' featured images without any text.

[Resolved] Can I call 5 recent posts' featured images without any text.

  • I would like to show the featured images of the five most recent posts on the home page without any text. When a user clicks the image they are taken to the related post. Doesn’t sound that hard, huh?

    Images will be uploaded in both orientations, landscape and vertical, but everything I’ve tried so far wants every “thumbnail” to be the same size, or at least fit in the same size box. I would like to specify a maximum width

    It doesn’t have to be the featured image. Perhaps the first image? The big deal is no text.

    Would it be easier to call the images without worrying about their size? They don’t need to be re sized, they can be uploaded in the right size.

    Can anyone point me in the right direction, please?

Viewing 2 replies - 1 through 2 (of 2 total)
  • Moderator Michael


    Forum Moderator

    to get the latest 5 posts with a featured image:

    <?php $recent = new WP_Query( array( 'posts_per_page' => 5, 'meta_key' => '_thumbnail_id' ) );
    if( $recent->have_posts() ) : while( $recent->have_posts() ) : $recent->the_post();
    echo '<a href="'; the_permalink(); echo '">';
    echo '</a>';
    endwhle; endif; wp_reset_postdata(); ?>



    if the ‘post_thumbnail’ settings and parameters don’t get the image size right, try to use css.

    if you want to use post’s images, there is a versatile plugin ‘get the image’ which you could try to use alternatively with a query which is not restricted to get only posts with featured image;
    change the first line of the code:

    <?php $recent = new WP_Query( array( 'posts_per_page' => 5 ) );

    Thank you so much for the fast response. I’ve been dying to get back to my desk to try this out. Since I’m new at this I just pasted that snippet into a few places (one at a time) but did not have any success. Am I using that in index.php or elsewhere?

    Once I get this current project behind me I think I’ll have to spend a few days going over the codex more thoroughly. In the past I’ve always stuck to modifying CSS and adding plugins.

Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘[Resolved] Can I call 5 recent posts' featured images without any text.’ is closed to new replies.