Support » Fixing WordPress » How to display most recent post with thumbnail and excerpt

  • Resolved pinksharpii


    For my website I’m trying to get the most recent post summary to be displayed in the footer across all pages.
    I couldn’t get the_excerpt() to work at all with

      $args = array( 'numberposts' => '1' );
      $recent_posts = wp_get_recent_posts( $args );
      foreach( $recent_posts as $recent ){?>
          <div class="summary"><?php echo '<a href="' . get_permalink($recent["ID"]) . '" title="Read More '.$recent["post_title"].'" >' . substr($recent["post_content"], 0 , 150) .'</a> '; ?></div>
    <?php echo the_post_thumbnail($recent->ID, 'thumbnail'); ?>
      <?php } ?>

    hence the substr with post_content.
    But what’s really tripping me up is the thumbnail.
    I want this displayed on all pages. On the home page and other pages which do not, of course, have a thumbnail image, nothing displays. But on pages (like specific product pages for our shop) the product thumbnail is displayed. Obviously this is not what I want. Nor does it make sense. I’m passing it $recent->ID so it should always display the thumbnail that corresponds with the most recent post. The text and title and perma of the recent post work just fine.
    What do I need to do to display the recent post’s thumbnail?

Viewing 3 replies - 1 through 3 (of 3 total)
  • Kindly try like this

     $postslist = get_posts('numberposts=3&order=DESC&orderby=date');
     foreach ($postslist as $post) :
     <div class="entry">
     <h3><a href="<?php the_permalink(); ?>"><?php the_title(); ?></a></h3>
     <?php the_time(get_option('date_format')) ?>
     <?php the_excerpt(); ?>
     <?php endforeach; ?>

    omgosh, yes, this worked. So simply too! Thanks so much!!



    This was a big help, thanks!

Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘How to display most recent post with thumbnail and excerpt’ is closed to new replies.