Featured image of post wordpress重新生成缩略图

wordpress重新生成缩略图

使用wp-cli批量重新生成缩略图

安装wp-cli

wp-cli是一个管理wordpress的命令行界面

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
#下载wp-cli.phar文件:wget or curl
curl -O https://raw.githubusercontent.com/wp-cli/builds/gh-pages/phar/wp-cli.phar
#接下来,检查Phar文件以验证其是否正常运行:
php wp-cli.phar --info
#要通过在命令行中输入来使用WP-CLI,请使文件可执行,然后将其移动到PATH中的某个位置。例如:
chmod +x wp-cli.phar
mv wp-cli.phar /usr/local/bin/wp
#如果成功安装了WP-CLI,则在运行时应会看到类似以下内容wp --info:
$ wp --info
OS:    Darwin 16.7.0 Darwin Kernel Version 16.7.0: Thu Jan 11 22:59:40 PST 2018; root:xnu-3789.73.8~1/RELEASE_X86_64 x86_64
Shell:    /bin/zsh
PHP binary:    /usr/local/bin/php
PHP version:    7.0.22
php.ini used:   /etc/local/etc/php/7.0/php.ini
WP-CLI root dir:        /home/wp-cli/.wp-cli/vendor/wp-cli/wp-cli
WP-CLI vendor dir:        /home/wp-cli/.wp-cli/vendor
WP-CLI packages dir:    /home/wp-cli/.wp-cli/packages/
WP-CLI global config:   /home/wp-cli/.wp-cli/config.yml
WP-CLI project config:
WP-CLI version: 2.4.0
#您可以使用wp cli update 或通过重复安装步骤来更新WP-CLI 。

选项

1
2
3
4
5
[<attachment-id>…]-要重新生成附件的一个或多个ID。  
[–image_size=<image_size>]-要重新生成的图像大小的名称。将仅重新生成此图像尺寸的缩略图,而不会重新生成其他图像尺寸的缩略图。  
[–skip-delete]-跳过原始缩略图的删除。如果缩略图是从控件之外的来源链接的,则最好将其保留。默认为false。  
[–only-missing]-仅为缺少图像尺寸的图像生成缩略图。  
[–yes]-对确认消息回答是。仅当没有ID作为参数传递时才显示确认。

例子

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
# Regenerate thumbnails for given attachment IDs.
$ wp media regenerate 123 124 125
Found 3 images to regenerate.
1/3 Regenerated thumbnails for "Vertical Image" (ID 123).
2/3 Regenerated thumbnails for "Horizontal Image" (ID 124).
3/3 Regenerated thumbnails for "Beautiful Picture" (ID 125).
Success: Regenerated 3 of 3 images.

# Regenerate all thumbnails, without confirmation.
$ wp media regenerate --yes
Found 3 images to regenerate.
1/3 Regenerated thumbnails for "Sydney Harbor Bridge" (ID 760).
2/3 Regenerated thumbnails for "Boardwalk" (ID 757).
3/3 Regenerated thumbnails for "Sunburst Over River" (ID 756).
Success: Regenerated 3 of 3 images.

# Re-generate all thumbnails that have IDs between 1000 and 2000.
$ seq 1000 2000 | xargs wp media regenerate
Found 4 images to regenerate.
1/4 Regenerated thumbnails for "Vertical Featured Image" (ID 1027).
2/4 Regenerated thumbnails for "Horizontal Featured Image" (ID 1022).
3/4 Regenerated thumbnails for "Unicorn Wallpaper" (ID 1045).
4/4 Regenerated thumbnails for "I Am Worth Loving Wallpaper" (ID 1023).
Success: Regenerated 4 of 4 images.

# Re-generate only the thumbnails of "large" image size for all images.
$ wp media regenerate --image_size=large
Do you really want to regenerate the "large" image size for all images? [y/n] y
Found 3 images to regenerate.
1/3 Regenerated "large" thumbnail for "Sydney Harbor Bridge" (ID 760).
2/3 No "large" thumbnail regeneration needed for "Boardwalk" (ID 757).
3/3 Regenerated "large" thumbnail for "Sunburst Over River" (ID 756).
Success: Regenerated 3 of 3 images.

官方说明:https://developer.wordpress.org/cli/commands/media/regenerate/

使用 Hugo 构建
主题 StackJimmy 设计