Wordpress为您的照片内置大小,当您上传图像时,它会自动创建这些大小。
您可以使用
get_the_post_thumbnail( $post_id, \'thumbnail\' ); // Thumbnail (Note: different to Post Thumbnail)
get_the_post_thumbnail( $post_id, \'medium\' ); // Medium resolution
get_the_post_thumbnail( $post_id, \'large\' ); // Large resolution
get_the_post_thumbnail( $post_id, \'full\' ); // Original resolution
如果这些不完全符合您的要求,您也可以创建自己的尺寸:
add_image_size( \'my-custom-size\', 220, 180 ); // 220 pixels wide by 180 pixels tall, soft proportional crop mode
然后按上述方法调用:
get_the_post_thumbnail( $post_id, \'my-custom-size\' );