Wordpress:从图像ID获取描述,标题,alt,文件URL,而图像不是后缩略图 [英] Wordpress: Get description, caption, alt, file URL, from an image ID without the image being a post thumbnail

查看:501
本文介绍了Wordpress:从图像ID获取描述,标题,alt,文件URL,而图像不是后缩略图的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在为wordpress写一个短代码

I am writing a shortcode for wordpress

[insert_image id="#NUM"]

代码说明:代码查找图片编号#NUM并检索所有信息,例如:alt测试,描述,标题,标题,文件URL等。此信息用于以类似于维基百科的方式格式化图像(顶部的标题,然后是图像,底部的描述,然后信用到摄影师,所有人都装在一个带阴影的盒子里:))。

Description of the code: The code looks up the image number #NUM and retrieve all the information such as: alt test, description, title, caption, file URL, etc. This information is used to format the image in a way that is similar to Wikipedia (caption on top, then the image, description in the bottom and then the credit to the photographer, all framed in a box with shadow :)).

我是如何解决这个问题的:不幸的是网上有很多检索缩略图属性的东西,但很少关于未附加到帖子的图像,就像在这种情况下一样。当我了解到图像被视为Wordpress中的帖子时,我试图检索id为图像id的帖子,但Wordpress返回NULL。尝试其他方式,但获得了一些关于图片的信息,如宽度和高度,但不是我正在寻找的信息。我甚至查看了显示图像属性添加图像 - >媒体库的Wordpress代码,但我无法找到答案(代码对我来说太高级了)。

How I tried to sort this out: Unfortunately online there is a lot of stuff on retrieving thumbnails properties, but little about images that are NOT attached to the post, as it is in this case. As I learned that the image is treated as a post in Wordpress, I tried to retrieve the post whose id is the id of the image, but Wordpress returned NULL. Tried other ways, but got some information on the picture like width and height, but not the information I was looking for. I even looked at the Wordpress code that displays the image properties "add an image"->"media library", but I was not able to find the answer (that code is too advanced for me).

问题:所以,我想知道是否有人可以帮助我检索与id识别但未附加到帖子上的图像相关的所有礼物?

Question: So, I wonder is there anyone that can help me retrieve all the proprieties associated with an image identified just by the id but NOT attached to the post?

推荐答案

尝试 wp_prepare_attachment_for_js

我还没有使用它,但我知道它应该从附件中获取所有信息,包括标题,描述,替代,标题等。

I have yet to use it, but I know its supposed to grab all the information from an attachment including title, description, alt, caption, etc.

这篇关于Wordpress:从图像ID获取描述,标题,alt,文件URL,而图像不是后缩略图的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆