Support » Themes and Templates » Show featured image (and only featured image)

  • Resolved ksteingrandt

    (@ksteingrandt)


    Hi all

    I am using WP 3.3 with the Twenty Eleven theme, straight up out of the box. I would like to simply show each post’s featured image on the blog’s home page, NOT the image that is inserted into the post.

    I am using Twenty Eleven out of the box, where index.php is the home page (showing latest posts). I just would like to insert the featured image to the left of the excerpt, and exclude any other images from showing up there. Basically a very typical blog layout, nothing unusual or fancy.

    After mucking around a bit, it looks like the default is the exact opposite – show images that are inserted into posts, but don’t show featured images at all.

    The out-of-the-box code for Twenty Eleven’s index.php is:

    [code moderated per forum rules – please use the pastebin]

    I’m assuming (having almost no php experience!) is that the part I need to modify/add to is
    <?php get_template_part( 'content', get_post_format() ); ?>

    I just don’t know what to do with this. What do I need to add here to show the featured image along with the title, meta bar and excerpt, and not show images inserted into posts? Will I need to break out each element (title, meta bar, excerpt, thumbnail and footer meta), since right now it just seems to be pulling everything?

    I assume once that’s all done I’ll need to do some styling to align everything, which I should be able to handle .

    Here’s the site right now (it’s just plain old Twenty Eleven): http://ec2-50-19-26-13.compute-1.amazonaws.com/blogs/mgck/

    And yes, theme support for featured images is enabled 🙂

    Thanks everyone!

Viewing 3 replies - 1 through 3 (of 3 total)
  • Anyone? Bueller? Seems like this wouldn’t be a difficult topic to address?

    please don’t edit Twenty Elven directly, but create a child theme http://codex.wordpress.org/Child_Themes to work with.

    it is vital to have an unedited default theme (which is Twenty Eleven in wp3.3) in case of problems.
    a child theme also helps to keep any customisation during the next upgrade.

    to your question:

    the ‘get_template_part( ‘content’, get_post_format() )’ points to the template file content.php where you can make the edits.

    if you haven’t read this yet:
    http://codex.wordpress.org/Post_Thumbnails
    http://codex.wordpress.org/Function_Reference/the_excerpt

    Thanks a bunch! I did actually create a child theme, so no worries 🙂

    For anyone who stumbles across this via a search, here are the step-by-step details (I always get frustrated when there are no step-by-step instructions in a support thread)

    For basic usage, you need to put this

    <?php
    if ( has_post_thumbnail() ) { // check if the post has a Post Thumbnail assigned to it.
      the_post_thumbnail();
    }
    ?>

    in content.php within the div called “entry-content”

    So, the whole div will look like this once you’re done:

    <div class="entry-content">
    			<?php if ( has_post_thumbnail() ) { // check if the post has a Post Thumbnail assigned to it.
      					the_post_thumbnail();
    					}
    					?>
    					<?php the_content( __( 'Continue reading <span class="meta-nav">→</span>', 'twentyeleven' ) ); ?>
    			<?php wp_link_pages( array( 'before' => '<div class="page-link"><span>' . __( 'Pages:', 'twentyeleven' ) . '</span>', 'after' => '</div>' ) ); ?>
    		</div>

    Then style as needed (I just added float: left and some padding to my stylesheet)

    You can also change the size of your thumbnails in functions.php in the set_post_thumbnail_size line

    Read the Codex links alchymyth supplied for different ways to configure post thumbnails (such as adding links to the thumbnails).

Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘Show featured image (and only featured image)’ is closed to new replies.