[resolved] display latest post with image on homepage (4 posts)

  1. bodhidude
    Posted 4 years ago #

    Hey there
    I'm creating a box on my homepage that shows the latest single post. I know how to create a query and a loop to show the latest post but I want to display the image associated with that post if there is one. What would be the best way to do this? Basically what I want is to display the post title, excerpt and a thumbnail of any image included in the latest post (if there is one).

  2. Caroline Moore
    Posted 4 years ago #

    Provided you've enabled Post Thumbnails in functions.php, the_post_thumbnail() should do the trick.

  3. Digital Raindrops
    Posted 4 years ago #

    This is from a modified twenty eleven child theme, content-excerpt.php.

    Have a look at the entry-summary section, I add a div and a right margin for a better look!

    <div class="entry-summary">
      <?php if( has_post_thumbnail()) : ?>
        <div class="alignleft" style="margin-right: 1em;">
          <?php the_post_thumbnail('thumbnail'); ?>
      <?php endif; ?>
      <?php the_excerpt(); ?>
    </div><!-- .entry-summary -->



  4. bodhidude
    Posted 4 years ago #

    ah yes post thumbnails, thank you

Topic Closed

This topic has been closed to new replies.

About this Topic