• On my static front page I have created, I query the WordPress Loop to only show the two most recent blog posts. For some reason, it started displaying two instances of the attached image for each post. Here is what it looks like.

    I have no idea why it is outputting two of the attached images for each.
    Here is the code for this specific part of front-page.php:

    <div class="row">
        <?php $latest = new WP_Query('showposts=2'); ?>
        <?php while( $latest->have_posts() ) : $latest->the_post(); ?>
    
        <a href='<?php echo get_permalink(); ?>'>
        <div class="col-md-6 blog-wrap">
    
        <?php $src = wp_get_attachment_image_src( get_post_thumbnail_id($post->ID), array( 5600,1000 ), false, '' ); ?>
            <div class="home-featured-img" style="background: url(<?php echo $src[0];?>);"></div>
    
            <div class="excerpt-home">
            <?php get_template_part( 'content', get_post_format() ); ?>
            </div>
        </div></a>
        <?php endwhile; ?>
    
    </div>

    I have a feeling that the problem occurs when I call:

    <?php $src = wp_get_attachment_image_src( get_post_thumbnail_id($post->ID), array( 5600,1000 ), false, '' ); ?>
    <div class="home-featured-img" style="background: url(<?php echo $src[0];?>);"></div>

    I only want for the post to display the image from this (which is the top picture):

    If you need any other code snippets from my custom theme, please let me know.

    Any and all suggestions are greatly appreciated.

Viewing 1 replies (of 1 total)
  • It comes from what’s inside the content template

    <?php get_template_part( 'content', get_post_format() ); ?>

    Also, the background image in div is a wrong way of putting an image there, it will not look right in responsive situation (try viewing the site in smaller screen.)

    Since the content template already output featured image, there is no need to output extra one. If you want the image to span full at the top, just remove the image element out of its container and adjust margins/paddings.

Viewing 1 replies (of 1 total)
  • The topic ‘Post's Attached Images Not Showing Up Correctly on Custom front-page.php’ is closed to new replies.