我最近添加了三种新尺寸的post\\u缩略图的主题支持,我想调整之前上传的所有旧图像的大小。我自己写的剧本如下:
function resizeImages()
{
require ( ABSPATH . \'wp-admin/includes/image.php\' );
global $wpdb;
$images = $wpdb->get_results( "SELECT ID FROM $wpdb->posts WHERE post_type = \'attachment\' AND post_mime_type LIKE \'image/%\' ORDER BY ID DESC");
foreach ($images as $image)
{
$fullsizepath = get_attached_file( $image->ID );
$metadata = wp_generate_attachment_metadata( $image->ID, $fullsizepath );
// If this fails, then it just means that nothing was changed (old value == new value)
if (wp_update_attachment_metadata( $image->ID, $metadata ))
{
echo $fullsizepath . " resized" . "<br/>";
}
}
}
通过wordpress上传的图像效果很好,但我已经通过php添加了一些图像。有问题的图像是用爬虫从我们的旧站点中提取的,并作为正确ID的子项添加到数据库中。我可以使用索引上的get\\u子项检索所有图像。php页面和上的单个。php,但由于某些原因,它们没有被调整大小。有人能帮忙吗?