can the_excerpt function also get images?

Not sure if im going about this in the right way but, overall, ive been told to create, kind of like a news box on my home page and so, the “latest news” is going to be this clients posts.

now i know i can control the_excerpts(); content length etc but, i cant seem to find any way for it to also allow an image.

when i showed the client the “news box” he wants whatever image is associated with the post, to come through.

so i thought of "the_content();" but i dont think thats what i need(though im not sure which one will work best with what i need)

so the main questions here for me are

  1. Can i somhow get the image to come through with the excerpt, or
  2. If the excerpt function doesnt allow it, then what can i use?

3 Answers
3

Ensure that your Theme supports Post Thumbnails, and that the client sets a “Featured Image” for each post. Then, combine the_excerpt() with the_post_thumbnail(), e.g. like so:

<?php
if ( have_posts() ) : while ( have_posts() ) : the_post();

    ?>
    <div id="post-<?php the_ID(); ?>" <?php post_class(); ?>>

        <div class="featured-image"><?php the_post_thumbnail(); ?></div>
        <div class="post-excerpt"><?php the_excerpt(); ?></div>

    </div>
    <?php

endwhile; endif;
?>

Then, just use CSS to style according to your needs.

Leave a Comment