我试图在标签页的相应存档中显示第一篇文章的特色图像。
我使用的模板是2017。通过插入以下代码,我已经看到了该图像:
if (is_tag() && have_posts()) {
echo \'<div class="single-featured-image-header">\';
the_post();
echo get_the_post_thumbnail( get_the_ID(), \'twentyseventeen-featured-image\' );
rewind_posts();
echo \'</div><!-- .single-featured-image-header (custom for tag archive)-->\';
}
正常特征图像的代码基本相同,只是条件不同:
if ((is_single() || (is_page() && !twentyseventeen_is_frontpage())) && has_post_thumbnail(get_queried_object_id())) {
echo \'<div class="single-featured-image-header">\';
echo get_the_post_thumbnail( get_queried_object_id(), \'twentyseventeen-featured-image\' );
echo \'</div><!-- .single-featured-image-header -->\';
}
虽然我可以看到图像,但它显示的图像比正常的特征图像小。存档页面上的图像具有以下标记:
<img
src="https://hongkong-rocks.com/wp-content/uploads/2019/07/4H8A5933.jpg"
class="attachment-twentyseventeen-featured-image size-twentyseventeen-featured-image wp-post-image"
alt=""
srcset="https://hongkong-rocks.com/wp-content/uploads/2019/07/4H8A5933.jpg 1280w, https://hongkong-rocks.com/wp-content/uploads/2019/07/4H8A5933-300x200.jpg 300w, https://hongkong-rocks.com/wp-content/uploads/2019/07/4H8A5933-768x512.jpg 768w, https://hongkong-rocks.com/wp-content/uploads/2019/07/4H8A5933-1024x682.jpg 1024w"
sizes="(max-width: 767px) 89vw, (max-width: 1000px) 54vw, (max-width: 1071px) 543px, 580px"
width="1280"
height="853">
正确的显示帖子特征图像如下:
<img
src="https://hongkong-rocks.com/wp-content/uploads/2019/07/4H8A5933.jpg"
class="attachment-twentyseventeen-featured-image size-twentyseventeen-featured-image wp-post-image"
alt=""
srcset="https://hongkong-rocks.com/wp-content/uploads/2019/07/4H8A5933.jpg 1280w, https://hongkong-rocks.com/wp-content/uploads/2019/07/4H8A5933-300x200.jpg 300w, https://hongkong-rocks.com/wp-content/uploads/2019/07/4H8A5933-768x512.jpg 768w, https://hongkong-rocks.com/wp-content/uploads/2019/07/4H8A5933-1024x682.jpg 1024w"
sizes="100vw"
width="1280"
height="853">
所以我有相同的类,但由于某些原因注入了这些大小,我不知道如何影响这一点。
有人知道如何影响这些注射尺寸吗?
您可以在此处看到存档页面:https://hongkong-rocks.com/tag/mutant-monster/ 这张帖子的特色图片如下所示:https://hongkong-rocks.com/2019/07/20/mutant-monster-2/
这是标题。php模板:https://pastebin.com/2wJk4EAz
最合适的回答,由SO网友:uncovery 整理而成
所以我找到了问题所在。2017主题在函数中有一个内置函数。php可以做到这一点:
添加自定义图像大小属性以增强后期缩略图的响应图像功能
function twentyseventeen_post_thumbnail_sizes_attr( $attr, $attachment, $size )
其中有一个if(is\\u archive())条件。我必须使用更高优先级的自定义函数重写该函数,并在该自定义函数中删除is\\u archive()条件。