Col*_*ole 2 php wordpress image
我知道如何在PHP中使用add_image_size来注册可以在模板中使用的新大小.当它们上传时,它也会以这种尺寸制作图像.
我添加的大小不会在管理员中显示.
那2个问题......
当博主发布新帖子时,如何才能在"上传图片"中显示我制作的图片尺寸?
有没有办法在管理员中列出它,以便博客可以添加新的,而无需更改PHP代码?
或者我做错了什么,比如不把add_image_size调用放在正确的位置/文件中?这样的尺寸应该出现在上传菜单部分吗?
油菜
Wordpress不会在媒体灯箱中显示自定义图像大小选项,但您可以使用attachment_fields_to_edit过滤器添加它们.以下内容将为您定义的所有自定义图像大小添加选项.
add_filter('attachment_fields_to_edit', 'my_attachment_fields_to_edit_filter', 100, 2);
function my_attachment_fields_to_edit_filter($form_fields, $post) {
if (!array_key_exists('image-size', $form_fields)) return $form_fields;
global $_wp_additional_image_sizes;
foreach($_wp_additional_image_sizes as $size => $properties) {
if ($size == 'post-thumbnail') continue;
$label = ucwords(str_replace('-', ' ', $size));
$cssID = "image-size-{$size}-{$post->ID}";
$downsize = image_downsize($post->ID, $size);
$enabled = $downsize[3];
$html = '<input type="radio" ' . disabled($enabled, false, false) . 'name="attachments[' . $post->ID. '][image-size]" id="' . $cssID . '" value="' . $size .'">';
$html .= '<label for="'. $cssID . '">' . $label . '</label>';
if ($enabled) $html .= ' <label for="' . $cssID . '" class="help">(' . $downsize[1] . ' × ' . $downsize[2] . ')</label>';
$form_fields['image-size']['html'] .= '<div class="image-size-item">' . $html . '</div>';
}
return $form_fields;
}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
1748 次 |
| 最近记录: |