$5
Get Post Attachments
I'm using the following code in my functions.php file:
And this code inside my loop:
There are two images attached to the post I'm working with, and this code ($imgurl) returns the same image twice. Obviously I want it to return the URL for each image...
<?php
function get_images($size = 'thumbnail') {
global $post;
return get_children( array('post_parent' => get_the_ID(), 'post_status' => 'inherit', 'post_type' => 'attachment', 'post_mime_type' => 'image', 'order' => 'ASC', 'orderby' => 'menu_order ID') );
}
if ($images = get_images()) {
foreach ($images as $image) {
$imgtitle = $image->post_title;
$imgurl = wp_get_attachment_url($image->ID);
}
}
?>And this code inside my loop:
<?php
$photos = get_images('full');
if ($photos)
{
foreach ($photos as $photo)
{
echo('<div class="image"><img src="'.$imgurl.'" /><span class="title">'.$imgtitle.'</span></div>');
}
}
?>There are two images attached to the post I'm working with, and this code ($imgurl) returns the same image twice. Obviously I want it to return the URL for each image...
Dan Davies | 04/28/10 at 4:27pm
| Edit
(1) Possible Answers Submitted...
-

Last edited:
04/28/10
4:42pmUtkarsh Kukreti says:<?php
$photos = get_images('full');
if ($photos)
{
foreach ($photos as $photo)
{
echo('<div class="image"><img src="'.wp_get_attachment_url($photo->ID).'" /><span class="title">'.$photo->post_title.'</span></div>');
}
}
?>Previous versions of this answer: 04/28/10 at 4:41pm
- 04/28/10 4:36pm
Dan Davies says:That just returns a blank page.
- 04/28/10 4:41pm
Utkarsh Kukreti says:Try now.
- 04/28/10 4:42pm
Dan Davies says:Nice job, thanks.
- 04/28/10 4:36pm
This question has expired.
Current status of this question: Completed




