Member
Member
Rain   2008-12-17, 11:35
#1
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 "</div'>";
}
?>
`
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.
Administrator
Administrator
acrylian   2008-12-17, 11:53
#2
`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()`
Member
Member
Rain   2008-12-17, 12:15
#3
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!
Member
Member
Rain   2008-12-17, 12:48
#4
`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?
Administrator
Administrator
acrylian   2008-12-17, 13:00
#5
Sure, `echo $_zp_gallery->getNumImages()`.
Member
Member
Rain   2008-12-17, 13:29
#6
Oh excellent! What about the "Albums 1-20 of 28" if I've set Zenphoto to show 20 albums per page for example?
Administrator
Administrator
acrylian   2008-12-17, 14:20
#7
`$_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.
Member
Member
sbillard   2008-12-17, 20:57
#8
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.
Member
Member
Rain   2008-12-17, 21:44
#9
Thanks! Clean code = good code.
  
Powered By MyBB, © 2002-2026 MyBB Group.
Made with by Curves UI.