简体   繁体   English

在自定义的front-page.php上,Wordpress Post的附加图像无法正确显示

[英]Wordpress Post's Attached Images Not Showing Up Correctly on Custom front-page.php

On my static front page I have created, I query the Wordpress Loop to only show the two most recent blog posts. 在我创建的静态首页上,我查询Wordpress循环以仅显示两个最新的博客文章。 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: 这是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: 我打给我时感觉出现了问题:

If you need any other code snippets from my custom theme, please let me know. 如果您需要我自定义主题中的其他任何代码段,请告诉我。

I only want for the post to display the image from this (which is the top picture): 我只希望帖子显示来自此的图像(这是顶部图片):

<?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>

Any and all suggestions are greatly appreciated. 任何和所有建议都将不胜感激。

you can remove any code like that 您可以删除任何类似的代码

<?php
        // Post thumbnail.
        twentyfifteen_post_thumbnail();
?>

Explanation... that file display the second image - the title - the meta you need to edit it to remove the code that display the image :) thats it. 说明...该文件显示第二个图像-标题-您需要对其进行编辑以删除显示图像的代码的元:)多数民众赞成。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM