Numbering images

By looking at another theme, I've managed to add the "Images 1-10 of 57" option to the album pages of the theme I'm working on by using the method below:

`
<?php
$firstImage = null;
$lastImage = null;
if ($myimagepage > 1) {
?>

<?php
}
while (next_image(false, $firstPageImages)) {
if (is_null($firstImage)) {
$lastImage = imageNumber();
$firstImage = $lastImage;
} else {
$lastImage++;
}
if (isLandscape()) {
$iw = 89;
$ih = NULL;
$cw = 89;
$ch = 67;
} else {
$iw = NULL;
$ih = 89;
$ch = 89;
$cw = 67;
}
echo '';
}
if (!is_null($lastImage) && $lastImage < getNumImages()) {
$np = getCurrentPage()+1;
?>

<?php
}
?>

<?php
if (!is_null($firstImage)) {
echo '<div class="count">';
printf(gettext('Images %1$u-%2$u of %3$u'), $firstImage, $lastImage, getNumImages());
echo "";
}
?>
`
I have two questions.
1. Is this the most efficient method of doing this?
2. Is there a way to display a similar function on the images page, ie "Image 4 of 57"? I suspect I have to change the `printf(gettext('Images %1$u-%2$u of %3$u'), $firstImage, $lastImage, getNumImages());` part to something else, but what?

Thanks a lot.

Comments

  • acrylian Administrator, Developer
    `echo "Image ". imageNumber()." of ".getNumImages()` for example. All documentated on our functions guide by the way.
    Since yout set the number of images per page you can use `getOption('images_per_page')` to calculate the x to y of z number thing.

    the `printf()/gettext()` in your example is just for translation support via gettext. If you don't need that at all you can skip that. Without this would read `echo "Images ".$firstimage." - ".$lastimage. " of ".getNumImages()`
  • Thanks, the "Image # of #" works beautifully. Though with this `echo "Images ".$firstimage." - ".$lastimage. " of ".getNumImages();` I get this output `Images - of 76`?

    Edit // Never mind, just had to change "firstimage" to "firstImage", and "lastimage" to "lastImage". Thanks for the help!
  • `getNumAlbums();` prints the number of total albums in the index, but is there a way to print the total number of images in all the albums as well? Couldn't find that in the functions guide. Same with returning something like "Albums 1-20 of 28" if I've set ZP to show 20 albums per page -- are these things possible?
  • acrylian Administrator, Developer
    Sure, `echo $_zp_gallery->getNumImages()`.
  • Oh excellent! What about the "Albums 1-20 of 28" if I've set Zenphoto to show 20 albums per page for example?
  • acrylian Administrator, Developer
    `$_zp_page` stores the index/album page you are currently on and `getOptions('albums_per_page')` gets, well obvious, isn't it...:-). For the total number of albums you already now it. Just do some calculating based on the page number to achieve that.
  • part of the code you have quoted is not related to the `n-m of p` so you can delete
    `
    if (isLandscape()) {
    $iw = 89;
    $ih = NULL;
    $cw = 89;
    $ch = 67;
    } else {
    $iw = NULL;
    $ih = 89;
    $ch = 89;
    $cw = 67;
    `
    being careful, of course to not screw up the if/else sets.

    look at the Effervescence+ theme customfunctions. It has a `printNofM()` function.
  • Thanks! Clean code = good code.
Sign In or Register to comment.