Hi guys.
I'm almost done, I can see the top of the mountain, but there is a string attached that won't let me make the final steps.
I need X random images on my start page. Don't want plugins, needs to be in a functions.php file. It all works nice, even with the spacing between the images and no spacer after the last one etc.
HOW DO I LIMIT THIS TO JUST ONE CATEGORY ?????
Please, someone help me exchange the "get_children" part for a good SQL thingie, with the JOIN LEFT and whatnot, to get only attachments from a certain category. I would be really, really grateful.
Here's my code:
function randomimage_mores($size=medium,$num=1) {
if ( $images = get_children(array(
'post_type' => 'attachment',
'category' => 'Fotos',
'numberposts' => $num,
'orderby' => 'rand()',
'post_mime_type' => 'image',)))
{
$zeiger = 1;
foreach( $images as $image ) {
if ($zeiger != $num) {
$zwischen=" ";
} else {
$zwischen = "";
$zeiger = 1;
}
$attachmenturl=wp_get_attachment_url($image->ID);
$attachmentimage=wp_get_attachment_image( $image->ID, $size );
echo '<a href="'.$attachmenturl.'" rel="lightbox">'.$attachmentimage.'</a>'.$zwischen;
$zeiger++;
}
} else {
echo "No Image";
}
}
You can see, I tried blindly using a "category" tag in the get_children, but to no avail. The "$zeiger" variable is there to see how many cycles I've done in the foreach loop, so that I do not add a spacer after the last image.
Please ... help!