Created
October 24, 2011 00:30
-
-
Save GreggFranklin/1308124 to your computer and use it in GitHub Desktop.
Get Attached Images from Post on Wordpress
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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