I'm using the following code in my functions.php file:
<?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...
Utkarsh Kukreti answers:
<?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>');
}
}
?>
Dan Davies comments:
That just returns a blank page.
Utkarsh Kukreti comments:
Try now.
Dan Davies comments:
Nice job, thanks.