Skip to content

Instantly share code, notes, and snippets.

@GreggFranklin
Created October 24, 2011 00:30
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save GreggFranklin/1308124 to your computer and use it in GitHub Desktop.
Save GreggFranklin/1308124 to your computer and use it in GitHub Desktop.
Get Attached Images from Post on Wordpress
<?php function postimage($size=thumbnail, $qty=-1) {
if ( $images = get_children(array(
'post_parent' => get_the_ID(),
'post_type' => 'attachment',
'numberposts' => $qty,
'post_mime_type' => 'image',)))
{
foreach( $images as $image ) {
$attachmenturl=wp_get_attachment_url($image->ID);
$attachmentimage=wp_get_attachment_image( $image->ID, $size );
echo '<meta property="og:image" content="'.$attachmentimage.'"/>';
}
} else {
echo "No Image";
}
} ?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment