I have made some slight progress, and if I use the following code, it properly lists the image TITLES (inside comments for testing). But how do I render the image permalinks, preferablly to the thumbnail size?
$args = array( 'post_type' => 'attachment', 'numberposts' => -1, 'post_status' => null, 'post_parent' => $post->ID );
$attachments = get_posts($args);
if ($attachments) {
foreach ( $attachments as $attachment ) {
$image = wp_get_attachment_url( get_attachment_link() );
print "<!-- " . apply_filters( 'the_title' , $attachment->post_title ) . " -->";
}
}
I can’t figure it out. I don’t understand the coding sufficiently to figure it out it seems.
In the first code example above: the result is every image in my database rendered. Don’t know why. But I feel the wp_get_attachment_url function would work with that code if I understood it better.
In the second example code above: I think the $args = array is limiting what data is pulled, but not sure. And I don’t think the wp_get_attachment_url function will work with that code.
In short, I take and splice code to meet my needs, but this is beyond my understanding. I’d be very grateful for someone with knowledge to step me through this.
Humbly,
Derek
You can try something like this:
<?php
$images = get_children( array(
'post_parent' => get_the_ID(),
'post_type' => 'attachment',
'post_mime_type' => 'image',
'numberposts' => -1
) );
foreach ( (array) $images as $image ) {
print wp_get_attachment_image( $image->ID, 'thumbnail' );
}
?>
Thanks Michael.
Just tried your code, but it gives results like this for each image:
<img width="150" height="150" src="http://www.derekbeck.com/1775/wp-content/uploads/2011/04/Battle-of-Lexington-April-19-1775-The-Plate-I-Amos-Doolittle-17751-150x150.jpg" class="attachment-thumbnail" alt="Battle of Lexington, April 19, 1775, The (Plate I) (Amos Doolittle, c. 1775)" title="Battle of Lexington, April 19, 1775, The (Plate I) (Amos Doolittle, c. 1775)" />
The code is indeed finding just those attachments on that post, but I need merely the url link (to feed into facebook meta information). Any thoughts on how to do that?
I tried putting the code
wp_get_attachment_url( $post_id )
in my header, but it renders nothing.
It doesn’t seem to fit in the code you offered above either.
Try like this:
<?php
$images = get_children( array(
'post_parent' => get_the_ID(),
'post_type' => 'attachment',
'post_mime_type' => 'image',
'numberposts' => -1
) );
foreach ( (array) $images as $image ) {
print wp_get_attachment_url( $image->ID );
}
?>
Now that works perfectly!
Thanks so very much, Michael! you are quite the expert!