Support » Fixing WordPress » Display Featured Image with latest post grab

  • Resolved Action Turtle


    Hey everyoneā€¦ I am at a loss šŸ™ I got this far but I am only able to pull a static image with the post to display on my home pageā€¦ I would like to dynamically display the featured image for the postā€¦ Here is the code I have so far

    <?php $the_query = new WP_Query( 'showposts=3' ); ?>
      <?php while ($the_query -> have_posts()) : $the_query -> the_post(); ?>
      <ul class="one_up tiles">
                  <!-- Get the single service -->
                  <li class="service">
                   <div class="two columns">
                   <img src="<?php echo get_template_directory_uri(); ?>/images/blogpost.png" alt="blog-post" /> 
                   <div class="nine columns">
                     <h3><a href="<?php the_permalink(); ?>"><?php the_title(); ?></a></h3>
                     <p><?php echo string_limit_words(get_the_excerpt(), 35); ?></p>

    I am pretty sure I need to put new code where it says img src=

    Does anyone know what code I need to dynamically grab the featured image for the post that I am pulling?

    Like for the words I was able to put (get_the_excerpt(), 35) to make sure I was not pulling the whole postā€¦

    Thank you so much for any helpā€¦

Viewing 3 replies - 1 through 3 (of 3 total)
  • You’ll want to replace the img tag with

    <?php the_post_thumbnail(); ?>

    Thanks so much for your help Marvinā€¦

    It seems to be working but for some reason I am getting the missing image display rather than the image that I have set to the featured imageā€¦

    I checked that I have thumbnail support enabled in my functions.php file

    I double check that images were definitely uploaded to the server and wordpress properly broke down the images into the proper resolutionsā€¦

    So I really don’t understand why I am getting the missing image tagā€¦ Thanks man

    Hey figured it out šŸ™‚

    I was doingā€¦

    <img src="<?php the_post_thumbnail(); ?>" />

    I needed to be doingā€¦

    <?php the_post_thumbnail(); ?>

    Funny that you actually need less code as wordpress get more advancedā€¦ Coolā€¦ Thanksā€¦

Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘Display Featured Image with latest post grab’ is closed to new replies.