WordPress:wp_get_attachment_thumb_url
似乎无法在主题中引用“大尺寸”、“中尺寸”或“小尺寸”图像。使问题更加复杂的是他们的命名约定 100 x ???文件名格式,防止对引用进行硬编码。有谁知道有什么解决办法吗?
There seems no way of referring to the "big size" "mid size" or "small size" image in a theme. Compounding that problem is their naming convention of 100 x ??? file name format, preventing hard coding a reference. Does anyone know of any solutions?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
您要使用的函数是
wp_get_attachment_image_src
,但它以向其传递有效附件 ID 的id
。 的“图库”选项卡中重新排序项目时设置的顺序:以下是如何拉回帖子上第一个附件的示例,它尝试按“menu_order”对其进行排序,这是您在“添加媒体”弹出窗口 需要注意的重要一点是,您可以传入
"thumbnail"
、"medium"
、"large"
和"full" 对应于“添加媒体”框中的相同尺寸。此外,它还返回一个数组:
编辑:您可以通过在 WordPress 后端的“系统 -> 媒体”下自定义它们来编辑 WordPress 创建的尺寸。
The function you want to use is
wp_get_attachment_image_src
, but it starts with passing it anid
of a valid attachment id. Here is an example of how to pull back the first attachment on a post, and it tries to order it by "menu_order" which is the order set when you reorder items in the "Gallery" tab of the "Add Media" popup:The important thing to notice is you can pass in
"thumbnail"
,"medium"
,"large"
and"full"
which correspond to the same sizes in the Add Media box. Also, it returns an array:EDIT: You can edit which sizes are created by WordPress by customizing them under "System->Media" in the WordPress backend.
使用 wp_get_attachment_thumb_url:
注意:您必须在循环内使用上面的代码片段,以便您可以获得 $post 变量。
to use wp_get_attachment_thumb_url:
NOTE: You MUST use the snippet above, inside the loop, so that you can get $post variable.
好吧,供大家以后参考...使用 WordPress 2.9 的新缩略图功能,您可以像这样指定不同的图像大小:
等等
。唉。我想这是每个搜索并找到此页面的人都会遇到的“呃”时刻之一。
Doug Neiner 和 Silent,非常感谢你们贡献的想法和答案。我会为你的努力+1,但事实证明答案比我们想象的要简单。
Ok, for everyone's future reference... using WordPress 2.9's new thumbnail feature, you can specify different image sizes like so:
etc.
Sigh. This is one of those "Duh" moments that I imagine everyone searching and finding this page will come to.
Doug Neiner and Silent, thank you both very much for your contributed thoughts and answers. I'll +1 for your efforts, but it turns out that the answer was simpler than we all thought.