允许使用 WordPress 的图库短代码自定义图像尺寸
在 WordPress 2.5 及更高版本中,有一个内置的图库功能,允许选择将图像库添加到 WordPress 博客上的帖子或页面。 (参考:http://codex.wordpress.org/Gallery_Shortcode)
您可以使用尺寸
选项指定您想要显示的缩略图大小。有效值包括“缩略图”、“中”、“大”和“完整”。默认为“缩略图”。 “缩略图”、“中”和“大”图像的大小可以在 WordPress 管理面板中配置。
IE。 [gallery size="medium"]
我的问题:我正在尝试破解 [gallery] 短代码以允许在输入时自定义尺寸 - 不是尝试通过管理面板执行此操作。我想使用类似 [gallery size="145x160"]
的内容。
与其下载一个臃肿的插件,我宁愿使用已有的插件,而且我不确定需要在文件结构中的何处进行更改。我熟悉 PHP,但我担心我会做出更改,然后当我更新 WP 的未来版本时,它会覆盖我已设置的内容。
有人可以帮我解决这个问题吗?
非常感谢!
In WordPress 2.5 and up, there's a built in Gallery feature that allows the option to add an image gallery to a Post or Page on your WordPress blog. (Ref: http://codex.wordpress.org/Gallery_Shortcode)
You can use a size
option to specify the thumbnail size you would like displayed. Valid values include "thumbnail", "medium", "large" and "full". The default is "thumbnail". The size of the images for "thumbnail", "medium" and "large" can be configured in WordPress admin panel.
ie. [gallery size="medium"]
My Question: I'm trying to hack up the [gallery] shortcode to allow for custom sizes at the time of input -- not trying to do this through the admin panel. I'd like to use something like, [gallery size="145x160"]
.
Rather then download a bloated plugin, I'd rather work with what's already there and I'm not sure where I need to go in my file structure to make the changes. I'm familiar with PHP but I'm afraid I'll make a change and then when I update future versions of WP, it will overwrite what I've set in motion.
Could someone help me out with this?
Thank you very much!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我知道这已经晚了,但我发现这个问题试图完成同样的事情。
图库没有任何内置过滤器来允许这样做,因此我开发了一个可以在下面使用的解决方案。
在主题的functions.php文件中,添加以下代码行:
这将中断正常的图库调用,修改正在使用的大小,然后调用内置的WordPress图库。
I know this is late, but I found this question trying to accomplish the same thing.
The Gallery does not have any built-in filters to allow this, so I developed a solution that works below.
In your theme's functions.php file, add the following lines of code:
This will interrupt the normal gallery call, revise the size being used, and then call the built-in WordPress gallery.
当您上传图像时,Wordpress 会将图像压缩为多种尺寸。因此,除非您在上传图像之前将其设置到管理面板,否则您无法获得给定尺寸的图像。
但您可以添加其他图像大小:
有关 Codex 上的 add_image_size() 的更多信息
Wordpress crunch the images in several size when you upload them. So you can not get your given size image unless you set it to the admin panel before uploading the image.
But you can add additional image size:
More about add_image_size() on Codex