In a recent Situation i needed to display the attachments of an WordPress Post, the Images, in a click-through-like manner. I also decided to display the current number in relation to the full number of Images you are currently looking at, like a simple “Picture 5 of 7″. Since there is no build in Option for that I had to build my own.
function getNumberOfSiblings($parentid){
$images = (get_children(array(
'post_parent' => $parentid,
'post_type' => 'attachment',
'post_mime_type'=> 'image',
)));
return count($images);
}
function getCurrentNumberOfSibling($parentid,$siblingid){
$images = (get_children(array(
'post_parent' => $parentid,
'post_type' => 'attachment',
'post_mime_type'=> 'image',
)));
if($images[$siblingid]->menu_order != 0){
return $images[$siblingid]->menu_order;
}else{
$i = count($images);
foreach($images as $image){
if($image->ID ==$siblingid){
return $i;
}
$i--;
}
}
}
I mainly just use the get_children function, in the first case to count all the returned siblings and in the second case to get the Position of the current Attachment I use the menu_order Attribute of that matter.