If anyone is curious I made a funciton myself. All you need to do is past this function into template-functions.php
function getNumCurrentImage() {
global $_zp_current_album, $_zp_current_image;
$result = query("SELECT * FROM ".prefix('images')." WHERE albumid = ".$_zp_current_album->albumid);
$current = '';
$counter = 1;
while($row = mysql_fetch_assoc($result)) {
if ($row['filename'] == $_zp_current_image->filename) {
$current = $counter;
}
$counter++;
}
return $current;
}
And post the following code in your theme's image.php file:
Photo of
Woo hoo.
I needed this function, too, and tested the above solutions but they seem to skip pictures all the time. Then I found the code in another post which worked fine unless you have album pagination enabeled: Then it skips all images on the pages following page 1:
http://www.zenphoto.org/support/topic.php?id=67
Here is my little hack based on the post above:
`function next_image() {
global $_zp_images, $_zp_current_image, $_zp_current_album, $_zp_page, $_zp_current_image_restore;
if (is_null($_zp_images)) {
$_zp_images = $_zp_current_album->getImages($_zp_page);
if (empty($_zp_images)) { return false; }
$_zp_current_image_restore = $_zp_current_image;
$_zp_current_image = new Image($_zp_current_album, array_shift($_zp_images));
save_context();
add_context(ZP_IMAGE);
return true;
} else if (empty($_zp_images)) {
$_zp_images = NULL;
$_zp_current_image = $_zp_current_image_restore;
restore_context();
return false;
} else {
$_zp_current_image = new Image($_zp_current_album, array_shift($_zp_images));
return true;
}
}`
`function next_image_all() { / Change the function name so that there's no conflict with original one /
global $_zp_images, $_zp_current_image, $_zp_current_album, $_zp_page, $_zp_current_image_restore;
if (is_null($_zp_images)) {
$_zp_images = $_zp_current_album->getImages(); /* Changed "getImages($_zp_images)" to "getImages()" */
if (empty($_zp_images)) { return false; }
$_zp_current_image_restore = $_zp_current_image;
$_zp_current_image = new Image($_zp_current_album, array_shift($_zp_images));
save_context();
add_context(ZP_IMAGE);
return true;
} else if (empty($_zp_images)) {
$_zp_images = NULL;
$_zp_current_image = $_zp_current_image_restore;
restore_context();
return false;
} else {
$_zp_current_image = new Image($_zp_current_album, array_shift($_zp_images));
return true;
}
}`
`
`
``
That's it. My PHP skills are mainly basic and I assume there might be a more elegant way but this works perfect for me. I implemented this hack on two website for clients recently (and a third one to come). Look here to see it in action:
www.christophclasen.de
www.eiscafe-tanduo.de/fotogalerien
Nevertheless there has been no feedback I did a little modification of the above solution. Now you can use it as a normal template function within image.php and it does not generate any useless code anymore.
Put this into a "custom_functions.php" for example, place this within your theme folder and call it via requre_once from image.php:
`
function next_image_all() { // this function is a little modification of the next_image()-function from the template_functions.php
global $_zp_images, $_zp_current_image, $_zp_current_album, $_zp_page, $_zp_current_image_restore;
if (is_null($_zp_images)) {
$_zp_images = $_zp_current_album->getImages();
if (empty($_zp_images)) { return false; }
$_zp_current_image_restore = $_zp_current_image;
$_zp_current_image = new Image($_zp_current_album, array_shift($_zp_images));
save_context();
add_context(ZP_IMAGE);
return true;
} else if (empty($_zp_images)) {
$_zp_images = NULL;
$_zp_current_image = $_zp_current_image_restore;
restore_context();
return false;
} else {
$_zp_current_image = new Image($_zp_current_album, array_shift($_zp_images));
return true;
}
}
function image_counter() {
$columns = 0;//set $columns as the counter
$current_pic = getImageTitle(true);
while (next_image_all()) {//open the loop
$columns++; //increment the counter so the first image = 1
if ($current_pic == getImageTitle())
{
echo $columns . " of " . getNumImages()." photos"; // modifiy this if you want to print anything else
}
}
}
`
You can call the counter with `` and it puts out something like "2 of 21 photos".
Maybe still not the most elegant way but it does what it's supposed to do and I am still a php rookie...
How about using DB queries, which will return the exact number of photos present in a given "id" (or album, or subalbum) depending on how it's configured. A lot simpler, and won't trouble you with pagination or skipping as it returns a count of images for a particular id. It's what I use. Still needs a bit of work in some places, but a DB query should return exactly what you are looking for number-wise, then you can do your counter math from there to do the 2 of 21 feature. You can also use the getNumImages function as well (which is built into Zenphoto).
Sample code:
`/ SQL Counting Functions /
function show_subalbum_count() {
$sql = "SELECT COUNT(id) FROM ". prefix("albums") ." WHERE parentid \"NULL\"";
$result = query($sql);
$count = mysql_result($result, 0);
echo $count;
}
function getIDforAlbum() {
if(!in_context(ZP_ALBUM)) return false;
global $_zp_current_album;
return $_zp_current_album->getAlbumID();
}
function show_sub_count_index() {
$id = getIDforAlbum();
$sql = "SELECT COUNT(*) FROM ". prefix("albums") ." WHERE parentid = $id";
$result = query($sql);
$count = mysql_result($result, 0);
echo $count;
}
`
Thanks for your feedback, thinkdreams. I already use the getNumImages function to get the number of all images in the current album. The real problem was to get the number of the current image. I am very new to php so using this little modification of the already existing next_image() function was a lot easier for me.
Interesstingly I never encountered any trouble regarding skipping images or pagination and it works perfectly with subalbums, too.
You probably have right but my basic php knowledge sadly does not really allow me to understand how to get your sugestion together with the counter... So of course I am open to any suggestions!
@thinkdreams: So I sat down and learnt/worked a little. Now I think I understood what you meant abobve. I think this one is better, image_counter() is now a function of its own:
`
/ Image counter like "1 of 23 Images" for use on image.php /
function image_counter() {
$id = getIDforAlbum();
// check if album images have sort_order. if not the id is taken as sorting method. Necessary especially for subalbums you can not sort currently.
$sql = "SELECT sort_order FROM images WHERE albumid = $id LIMIT 1,1";
$result = mysql_query($sql);
$check = mysql_result($result, 0);
if ($check === NULL)
{ $order = "id"; }
else
{ $order = "sort_order"; }
//and now the image counter
$sql = "SELECT albumid,filename,title FROM images WHERE albumid = $id ORDER BY $order";
$result = mysql_query($sql);
$number = 0;
while($row = mysql_fetch_array($result))
{
$number++;
$albumid[$number] = $row['albumid'];
$filename[$number] = $row['filename'];
$imagetitle[$number] = $row['title'];
}
$columns = 0;//set $columns as the counter
$current_pic = getImageTitle();
for ($columns = 1; $columns
I noticed that I forgot a lot "garbage code" and did a few things more complicated than necessary. So here is a more streamlined version:
`
/ Image counter like "1 of 23 Images" for image.php /
function image_counter() {
$id = getIDforAlbum();
// check if album images have sort_order. if not the id is take as sorting method. Necessary especially for subalbums you can not sort currently.
$sql = "SELECT sort_order FROM images WHERE albumid = $id LIMIT 1,1";
$result = mysql_query($sql);
$check = mysql_result($result, 0);
if ($check === NULL)
{ $order = "id"; }
else
{ $order = "sort_order"; }
//and now the image counter
$sql = "SELECT title FROM images WHERE albumid = $id ORDER BY $order";
$result = mysql_query($sql);
$number = 0;
while($row = mysql_fetch_array($result))
{
$number++;
if (getImageTitle() === $row['title'])
{ echo $number . " of " . getNumImages()." photos"; }
}
}
`