This function supports a number of our image gallery functions. The first is published on this page. There's also an article on our blog, "Find all Images (Except the Featured Image) Attached to a WordPress Post or Page", that discuses the WordPress functions in a little more depth.
Copy and paste the WordPress function into your theme's functions.php
file or, if you sensibly have one installed, your custom functions plugin.
1
<?php
2
/*
3
Return all Images (Except the Featured Image) Attached to a WordPress Post or Page
4
http://www.beliefmedia.com/wordpress-post-images
5
*/
6
7
8
9
10
'post_type' => 'attachment',
11
'posts_per_page' => -1,
12
'post_status' => 'any',
13
'post_parent' => $id,
14
15
);
16
17
/* Return array of all images */
18
if ($attachments) {
19
$i = 0; foreach ($attachments as $attachment) {
20
21
22
23
24
25
$images["$i"]['src'] = $imagesrc['0'];
26
$images["$i"]['medium_large'] = $imagesrc_medium_large['0'];
27
$images["$i"]['full'] = $imagesrc_full['0'];
28
$images["$i"]['thumbnail'] = $imagesrc_thumbnail['0'];
29
30
$images["$i"]['caption'] = $attachment->post_excerpt;
31
$i++;
32
}
33
}
34
35
return $images;
36
}