[英]Wordpress responsive post image sizes on mobile
I have added custom image sizes: 我添加了自定义图像尺寸:
add_image_size( 'post-thumb', 350, 350,true);
add_image_size( 'post-thumb-large', 767, 350,true);
add_image_size( 'post-single', 1200, 520,true);
<?php
if ( has_post_thumbnail() ) {
the_post_thumbnail( 'post-thumb' );
}
?>
<?php
if ( has_post_thumbnail() ) {
the_post_thumbnail( 'post-single' );
}
?>
I want from 400px to 767px all post images (and the single post image) to have the post-thumb-large
size and <=400px all post images to have post-thumb
size. 我希望从400px到767px的所有帖子图像(和单个帖子图像)都具有
post-thumb-large
尺寸,并且<= 400px所有帖子图像都具有post-thumb
尺寸。 I think the solution is with srcset
attribute, but where and how to add it ? 我认为解决方案是使用
srcset
属性,但是在哪里以及如何添加呢?
Please refer to this article on CSS-Tricks: https://css-tricks.com/responsive-images-youre-just-changing-resolutions-use-srcset/ 请参阅CSS-Tricks上的这篇文章: https : //css-tricks.com/response-images-youre-just-changing-resolutions-use-srcset/
Your transpiled HTML should look like this(according to the article above): 您转译的HTML应该如下所示(根据上述文章):
<img src="small.jpg" srcset="medium.jpg 1000w, large.jpg 2000w" alt="yah">
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.