Hi guys!
I'm trying to modify the Autofocus template, actually I quite stripped it down a bit =)
I would like to modify the home page retrieving a random image from each post instead of the last one.
function random_image_url($size=large) {
global $post;
if ( $images = get_children(array(
'post_parent' => get_the_ID(),
'post_type' => 'attachment',
'numberposts' => 1,
'orderby' => 'rand()',
'post_mime_type' => 'image',)))
{
foreach( $images as $image ) {
$attachmenturl=wp_get_attachment_image_src($image->ID, $size);
$attachmenturl=$attachmenturl[0];
echo ''.$attachmenturl.'';
}
} else {
echo '' . get_bloginfo ( 'stylesheet_directory' ) . '/img/no-attachment.gif';
}
}
that is the stripped down version of post_image_url with a different name (in case I mess it up :P).
I tried to add orderby=rand but to the get_children function, but doesn't work, any idea?
Cheers!