Show Excerpts and Post Thumbnail Twenty Eleven Theme

Adding post thumbnails and excerpts to Twenty Eleven theme is not much different than how they would be added to Twenty Ten.

The first step is to create a functions.php file for your child theme if you don’t already have one and add this to it. This adds our own custom size thumbnail of 140px X 140px.

I strongly recommend installing and running Ajax Rebuild Thumbnails plugin after completing this tutorial. It will create a new image size for each featured image. You can uninstall it after it’s finished.

// This sets the dimensions for the thumbnails displayed on the homepage
	add_image_size('excerpt-thumbnail', 140, 140, true);

The next step we need to tell our theme to display excerpts instead of the full post. Copy content.php to your child theme directory and open it. Find this block of code around line 35

		<?php if ( is_search() ) : // Only display Excerpts for Search ?>
		<div class="entry-summary">
			<?php the_excerpt(); ?>

Change it to this.

		<?php if ( is_search() | is_home() ) : // Edit this to show excerpts in other areas of the theme?>
		<div class="entry-summary">
		<!-- This adds the post thumbnail/featured image -->
			<div class="excerpt-thumb"><a href="<?php the_permalink(); ?>" title="<?php printf( esc_attr__( 'Permalink to %s', 'twentyeleven' ), the_title_attribute( 'echo=0' ) ); ?>" rel="bookmark">
		<?php the_post_thumbnail('excerpt-thumbnail', 'class=alignleft'); ?></a></div>
			<?php the_excerpt(); ?>

By adding | is_home() to the if statement it tells our theme to display excerpts on the homepage. I find doing it this way allows more control over which areas display excerpts and which display the full post.

Just below that you can see we’ve added the post thumbnail, the size of this is controlled by what we added to functions.php in the first step.

Now just save those two files and add a featured image to your posts and you’ll see post thumbnails with excerpts.

73 thoughts on “Show Excerpts and Post Thumbnail Twenty Eleven Theme

  1. Pingback:

    7 New Post/Page Features You Should About | webkracken

  2. Olaoluwa Awo

    Your articles are always awesome.
    How can this be applied to show multiple images (with the excerpt)?
    I tried adding two(2) featured images, but the latest image just replaced the previous one.

    Reply
    1. Zeaks

      Post author

      Hi Olaoluwa. I don’t think it’s possible to display 2 featured images in a post. There is probably a way to display images included in the post (I don’t know how without reading up on it), but there is only meant to be one featured image.

      Reply
  3. Hortensia

    Hello!
    And Great Learning!
    I just have one question…..
    I have included your code to show excerpts on my archive pages, bur how can I get the title to appear to the left to the image where the excerpt is located instead of having it above the image?
    Thanks!

    Reply
  4. sonal

    hi Zeak,
    i am facing the problem regarding the thumbnail on static page.
    after so many trials ,still it is not working properly.i mean only excerpt is working no thumbnail is der.
    can u pls help.
    thnks

    Reply
    1. Zeaks

      Post author

      Have you set a featured image for the static page? This tutorial is not for pages, but for blog posts. You’ll need to edit page.php instead of content.php if you’re trying to make it display on a page.

      Reply
  5. thevode

    NIce!, thanks, but I have a question. I’m using the actual version of Twenty Eleven and the excertp works, and the Ajar Plugin too, but not show the thimb, where I have to paste this code?:

    // This sets the dimensions for the thumbnails displayed on the homepage
    	add_image_size('excerpt-thumbnail', 140, 140, true);
    
    I have pasted it just above:
    
    function twentyeleven_excerpt_length( $length ) {
    	return 100;
    }
    add_filter( 'excerpt_length', 'twentyeleven_excerpt_length' );

    Into the functions.php 336 line.

    Thanks and congrats for your site!

    Reply
    1. Zeaks

      Post author

      Have you added a featured image to a post, and also added the code for the content.php? This should be used with a child theme, making changes to Twenty Eleven is just a bad idea.

      Reply
  6. Alex

    Thank you very much for the tutorial. One question, though: the code works, but the post list now extends outside the main page background. Is there a way to break the post list? Any idea how to fix this? Thank you very much in advance.

    Reply
    1. Zeaks

      Post author

      Hi Alex. The post area should not be doing that, nothing in the code I gave changes the layout of it. If you link your site I’ll take a look for you though.

      Reply

Leave a Reply