admin管理员组

文章数量:1201201

How do I list all the image(s) used on a specific WordPress page. I would like it to include the following if possible,

  • Url to image
  • Name of image
  • Url to thumbnail of the image

[Edit]
I would like to use WordPress itself to get the images, not use something like CURL and extract image urls. Also note this is back-end for a plugin.

[Edit 2]
I need to not only get images within the content of the page, but also images from the theme like a logo in the header, etc. Basically, all images that are on the entire page is what I'm trying to get

How do I list all the image(s) used on a specific WordPress page. I would like it to include the following if possible,

  • Url to image
  • Name of image
  • Url to thumbnail of the image

[Edit]
I would like to use WordPress itself to get the images, not use something like CURL and extract image urls. Also note this is back-end for a plugin.

[Edit 2]
I need to not only get images within the content of the page, but also images from the theme like a logo in the header, etc. Basically, all images that are on the entire page is what I'm trying to get

Share Improve this question edited Aug 23, 2015 at 1:21 Tom asked Aug 22, 2015 at 22:26 TomTom 1431 gold badge2 silver badges10 bronze badges 4
  • Questions in the form of "please do this for me" rarely receive answers. If you show an example of what you tried, where you researched a possible answer, etc you will find folks more willing to assist. – jdm2112 Commented Aug 23, 2015 at 0:24
  • @jdm2112 Hello, I have googled and done my research on this but so far I am unable to find anything that pulls image's urls from a specific page in WordPress. I do always try to find the answer myself before asking here. I would also like to add that this is not a "do this for me" question but more of a how do I go about accomplishing this – Tom Commented Aug 23, 2015 at 0:32
  • Are you trying to do this from the front-end or in the back-end, via a plugin for example. – jdm2112 Commented Aug 23, 2015 at 0:34
  • Backend (This is for a plugin), I will update my question – Tom Commented Aug 23, 2015 at 0:34
Add a comment  | 

1 Answer 1

Reset to default 1

The WP function get_attached_media() should provide the info you need.

If used in this way...

$media = get_attached_media( 'image' );

... the $media var should contain the wp_post objects for all attached images.

Function documentation in the WP Codex: https://developer.wordpress.org/reference/functions/get_attached_media/

本文标签: plugin developmentHow to list all images used on a specific page