Skip to content

Instantly share code, notes, and snippets.

@senlin
Created July 13, 2011 07:45
Show Gist options
  • Save senlin/1079895 to your computer and use it in GitHub Desktop.
Save senlin/1079895 to your computer and use it in GitHub Desktop.
show uploaded images on single-customposttype.php file
// use this only for the metabox script of Rilwis - http://www.deluxeblogtips.com/p/meta-box-script-for-wordpress.html#images
// the code below shows the image with a link to itself (to be used on thickbox overlays)
global $wpdb;
$meta = get_post_meta(get_the_ID(), 'sl_screenshots', false);
$meta = implode(',', $meta);
$images = $wpdb->get_col("
SELECT ID FROM $wpdb->posts
WHERE post_type = 'attachment'
AND ID in ($meta)
ORDER BY 'menu_order' ASC
");
foreach ($images as $image) {
// get image's source based on size, can be 'thumbnail', 'medium', 'large', 'full' or registered post thumbnails sizes
$src = wp_get_attachment_image_src($image, 'thumbnail');
$src = $src[0];
// add additional image source to show full image below
$srcfull = wp_get_attachment_image_src($image, 'full');
$srcfull = $srcfull[0];
// show image with link to its full size
echo "<a href='$srcfull'><img src='$src' /></a>";
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment