因此,对于,我添加了一些自定义图像大小,如下所示:
add_action(\'after_setup_theme\', \'image_sizes_setup\');
function image_sizes_setup(){
add_theme_support( \'post-thumbnails\' );
add_image_size(\'thumb-small-2x\', 196, 9999);
add_image_size(\'thumb-medium-2x\', 276, 9999);
add_image_size(\'portrait-thumb-large-2x\', 328, 9999);
add_image_size(\'landscape-thumb-large-2x\', 9999, 328);
add_image_size(\'small-2x\', 900, 600);
add_image_size(\'medium-2x\', 1200, 800);
add_image_size(\'large\', 1920, 1280);
add_image_size(\'large-large-2x\', 2160, 1440);
add_image_size(\'extra-large-2x\', 2400, 1600);
}
然后我编写了这段代码,以便在媒体管理器中选择它们
add_filter( \'image_size_names_choose\', \'custom_image_sizes_choose\' );
function custom_image_sizes_choose( $sizes ) {
$custom_sizes = array(
\'thumb-small-2x\' => \'Thumb Small\',
\'thumb-medium-2x\' => \'Thumb Medium\',
\'portrait-thumb-large-2x\' => \'Thumb Portrait Large\',
\'landscape-thumb-large-2x\' => \'Thumb Landscape Large\',
\'small-2x\' => \'Small\',
\'medium-2x\' => \'Medium\',
\'large\' => \'Large\',
\'large-large-2x\' => \'Large Large\',
\'extra-large-2x\' => \'Extra Large\',
);
return array_merge( $sizes, $custom_sizes );
}
我将它显示在我的一个模板中
add_action(\'genesis_after_header\', \'ts_show_featured_image\');
function ts_show_featured_image(){
if ( has_post_thumbnail()):
echo\'<div class="gallery header-image">\';
the_post_thumbnail( \'extra-large-2x\', array( \'class\' => \'featured-image\' ) );
echo \'</div>\';
endif;
}
img标记的html用作:
<img
width="2400"
height="1600"
src="http://example.com/wp-content/uploads/2016/04/Picture-6.jpg"
class="featured-image wp-post-image"
alt="Picture"
srcset="
http://example.com/wp-content/uploads/2016/04/Picture.jpg 2400w,
http://example.com/wp-content/uploads/2016/04/Picture-768x512.jpg 768w,
http://example.com/wp-content/uploads/2016/04/Picture-276x184.jpg 276w,
http://example.com/wp-content/uploads/2016/04/Picture-328x219.jpg 328w,
http://example.com/wp-content/uploads/2016/04/Picture-492x328.jpg 492w,
http://example.com/wp-content/uploads/2016/04/Picture-900x600.jpg 900w,
http://example.com/wp-content/uploads/2016/04/Picture-1200x800.jpg 1200w"
sizes="(max-width: 2400px) 100vw, 2400px"
>
所以一切都应该是这样的,只是2160x1440和1920x1280图像不在srcset中。它们的纵横比与其他所有缩略图相同(不包括缩略图,但这些都是无关紧要的。我甚至对缩略图大小和重新生成的缩略图进行了注释,以确保存在相同的问题)。
我试着做得很彻底,如果你需要更多信息,请告诉我。非常感谢!这快把我逼疯了。
So any ideas why they aren\'t showing up?