如何在 Wordpress 中更改默认图像缩略图大小
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/3725894/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
How To Change Default Image Thumbnail Sizes in Wordpress
提问by jeffkee
Hey.. quite embarrassed to ask this actually - I should be able to find this on Google, but because of all the new WP functionality as well as the older methods of doing this in older versions are riddled all over Google Results that I have resorted to leverage the knowledge of a good samaritan out there somewhere.
嘿.. 实际上很尴尬 - 我应该能够在 Google 上找到这个,但是由于所有新的 WP 功能以及在旧版本中执行此操作的旧方法在我使用的 Google 结果中到处都是千疮百孔在某处利用好撒玛利亚人的知识。
I already know how to set up custom thumbnail sizes (I'm developing a Magazine style theme), and at the moment I'm working on getting my gallery working. When I choose to "insert to post" an image, it gives me 4 options - small, medium and large thumbnails plus the original size.
我已经知道如何设置自定义缩略图大小(我正在开发一个杂志风格的主题),目前我正在努力让我的画廊工作。当我选择“插入以发布”图像时,它为我提供了 4 个选项 - 小、中、大缩略图加上原始尺寸。
I need to know, for embedding purposes (not the featured post thumbnails), how to set the default sizes of these thumbnails so that they appear in the Media section of the Post editing screen.
我需要知道,出于嵌入目的(不是精选帖子缩略图),如何设置这些缩略图的默认大小,以便它们出现在帖子编辑屏幕的媒体部分。
Any ideas?
有任何想法吗?
回答by jeffkee
I answered my own question folks, and I feel quite dumb.. haha.
我回答了我自己的问题,我觉得很愚蠢..哈哈。
It was in the Admin screen. Left bar.. Settings -> Media, and there they are. Thumbnail, medium, and large sizes. No file hacks, no custom size settings in the functions.php file necessary.
它在管理员屏幕中。左栏.. 设置 -> 媒体,它们就在那里。缩略图、中号和大号。没有文件黑客,在functions.php 文件中没有必要的自定义大小设置。
Oops!
哎呀!
回答by Valeriu Tihai
In function.php add this code:
在 function.php 中添加以下代码:
update_option( 'thumbnail_size_w', 250 );
update_option( 'thumbnail_size_h', 141 );
update_option( 'medium_size_w', 850 );
update_option( 'medium_size_h', 478 );
update_option( 'large_size_w', 1200 );
update_option( 'large_size_h', 675 );
Image Size Names : ‘thumb', ‘thumbnail', ‘medium', ‘large'
图像大小名称:'thumb'、'thumbnail'、'medium'、'large'
The names “thumb” and “thumbnail” are just aliases
名称“thumb”和“thumbnail”只是别名
回答by Todd Moses
Look in your wordpress root folder as such:
在你的 wordpress 根文件夹中查看:
wordpress_root\wp-includes
In this folder there is a file called: media.php
在这个文件夹中有一个名为: media.php
Starting on Line 34 there is a function:
从第 34 行开始,有一个函数:
function image_constrain_size_for_editor($width, $height, $size = 'medium')
in this function, starting on Line 41, there is the following code. Just edit this for your needs:
在这个函数中,从第 41 行开始,有以下代码。只需根据您的需要编辑它:
elseif ( $size == 'thumb' || $size == 'thumbnail' ) {
$max_width = intval(get_option('thumbnail_size_w'));
$max_height = intval(get_option('thumbnail_size_h'));
// last chance thumbnail size defaults
if ( !$max_width && !$max_height ) {
$max_width = 128;
$max_height = 96;
}
}