Php 修改Wordpress循环中的特色图像

Php 修改Wordpress循环中的特色图像,php,wordpress,loops,Php,Wordpress,Loops,所以我有一个修改过的Wordpress循环。任务是为每个帖子分配一个唯一的HTML结构 无论如何,我成功地使用了它。直到我添加了调用特征图像并使其成为背景图像的代码(css样式属性) 我现在遇到的错误是,它为所有帖子提取相同的特色图片。例如,对于第二到第六篇文章,它会显示与第二篇文章相同的特征图像 但我不确定。我认为这些代码应该放在某个地方,这样它就不会干扰循环并显示正确的图像 关于正确操作的任何建议?has\u post\u缩略图()接受post ID作为参数,使用has\u post\u缩略

所以我有一个修改过的Wordpress循环。任务是为每个帖子分配一个唯一的HTML结构

无论如何,我成功地使用了它。直到我添加了调用特征图像并使其成为背景图像的代码(css样式属性)

我现在遇到的错误是,它为所有帖子提取相同的特色图片。例如,对于第二到第六篇文章,它会显示与第二篇文章相同的特征图像

但我不确定。我认为这些代码应该放在某个地方,这样它就不会干扰循环并显示正确的图像


关于正确操作的任何建议?

has\u post\u缩略图()
接受post ID作为参数,使用
has\u post\u缩略图($post->ID)
。因为您使用的是修改后的循环,所以需要隐式地将post ID作为函数参数传递

虽然我现在还不能确定,但我猜通过使用
global$post获取id,您将获得第一篇文章的ID

由于您处于循环中,因此可以使用以下函数解决此问题:
获取_ID()
(见附件)

这将为您提供以下获取图像ID的方法:

 $imgID = get_post_thumbnail_id(get_the_ID()); //get the id of the featured image

我不确定,但我改了,但什么也没发生。它提取了不正确的特征图像。尝试了此操作,但没有发生任何事情。实际上,它可以在标记中使用,但问题是图像应该作为背景图像。这样,我可以调用我想要的大小。你能在web浏览器中打开网页并查看HTML源代码吗?你那里有多少人?似乎您正在循环中使用CSS样式声明,并且它会重复多次。我可以在浏览器中看到一个标记。如果它与tak一起工作,则您的CSS标记有问题。最简单的方法是使用这样的内联样式:

 $imgID = get_post_thumbnail_id($post->ID); //get the id of the featured image
    $featuredImage1 = wp_get_attachment_image_src($imgID, 'TypeTwo-1' );//get the url of the featured image (returns an array)
    $featuredImage2 = wp_get_attachment_image_src($imgID, 'TypeThree-2' );//get the url of the featured image (returns an array)

    $posttypetwoURL1 = $featuredImage1[0]; //get the url of the image out of the array
    $posttypetwoURL2 = $featuredImage2[0]; //get the url of the image out of the array
 $imgID = get_post_thumbnail_id(get_the_ID()); //get the id of the featured image