• Resolved jamonavich

    (@jamonavich)


    Okay, I’m using the twenty eleven theme, editing with a child theme.

    I’m trying to get a featured image to show up next to the post on the homepage, and also prevent the featured image from taking over the header on the actual posts’ page. Right now it is making every post on the homepage have the same featured image and still taking over the header.

    <?php
      $thumbnails = get_posts('numberposts=5');
      foreach ($thumbnails as $thumbnail) {
        if ( has_post_thumbnail($thumbnail->ID)) {
          echo '<a href="' . get_permalink( $thumbnail->ID ) . '" title="' . esc_attr( $thumbnail->post_title ) . '">';
          echo get_the_post_thumbnail($thumbnail->ID, 'thumbnail');
          echo '</a>';
        }
      }
    ?>

    The above is the code I added in to make the featured image show up on the homepage. Any help would be greatly appreciated.

    Here is the link to the site:

    http://www.legendarysweets.com/

Viewing 7 replies - 1 through 7 (of 7 total)
  • Where did you add this code in the child theme? Do you have a custom copy of the header.php file in your child theme? That’s where the “featured image banner” code is.

    Thread Starter jamonavich

    (@jamonavich)

    The code was added into content.php directly below the header code.

    I haven’t created a header.php file yet in my child theme. What would I need to do to the code in order to prevent the “featured image banner” feature?

    to show a thumbnail per post on the front page in a Twenty Eleven child, you can simply edit content.php (in the child theme) and add
    <?php the_post_thumbnail('thumbnail'); ?>
    into the existing code;
    for instance after this line 34:
    </header><!-- .entry-header -->

    or for a conditional and linked thumbnail:

    <?php if( has_post_thumbnail($post->ID) ) { ?>
    <a href="<?php the_permalink(); ?>"><?php the_post_thumbnail('thumbnail'); ?></a>
    <?php } ?>

    http://codex.wordpress.org/Function_Reference/the_post_thumbnail
    http://codex.wordpress.org/Function_Reference/has_post_thumbnail

    (obviously this will only show if the post has a ‘featured image’)

    Thread Starter jamonavich

    (@jamonavich)

    Way to go alchymyth! Worked like a charm.

    One other question though. How can I move the text to the right of the featured image?

    Also, if you’re up to it, I’m still looking for assistance on getting rid of the featured image banner.

    Thanks for the help guys.

    Thread Starter jamonavich

    (@jamonavich)

    Hey guys. After much googling I could still use some help on getting rid of the featured image banner, and also wrapping text around the featured image on the front page.

    try to add this to style.css of the child theme:

    .home .attachment-thumbnail { float: left; margin: 25px 10px 10px 0; }

    .home restricts this style to the posts page; and .attachment-thumbnail targets the post-thumbnail image.

    for the featured header banner, edit header.php and look closely at this well commented section (shortened below):

    <?php
    					// The header image
    					// Check if this is a post or page, if it has a thumbnail, and if it's a big one
    .....
    .....
    					else : ?>
    					<img src="<?php header_image(); ?>" width="<?php echo HEADER_IMAGE_WIDTH; ?>" height="<?php echo HEADER_IMAGE_HEIGHT; ?>" alt="" />
    				<?php endif; // end check for featured image or standard header ?>

    remove most of it and leave only this part:

    <img src="<?php header_image(); ?>" width="<?php echo HEADER_IMAGE_WIDTH; ?>" height="<?php echo HEADER_IMAGE_HEIGHT; ?>" alt="" />
    Thread Starter jamonavich

    (@jamonavich)

    Oh man, someone give this man a medal.

    Thanks alchymyth, all 3 of your solutions have saved me a ton of time. I really appreciate it.

Viewing 7 replies - 1 through 7 (of 7 total)
  • The topic ‘Same featured image appearing in every post on the front page’ is closed to new replies.