I am using the NextGen gallery WordPress plugin for a site. In my gallery.php template I want to retrieve the number of images for each gallery displayed in the loop. I cannot figure out a way to get the data and print it under the thumbnail of each gallery that’s called in gallery.php
Here is where I want to insert the gallery image count and print it:
<a rel="prettyPhoto" href="<?php echo $image->imageURL ?>"
<?php $image->thumbcode ?>><span>view</span></a> <?php echo $total_images; ?> pictures
Anybody have any tips?
Thanks,
Ian
I used this little hack to get my gallery id from the shortcode I pasted inside my post ([nggallery=1])
Hope my solution can work for you.
This is the code you need to count the images:
The answer is you can’t.
You can count the keys in the $images variable but it will return the wrong number.
You can retrieve the total number of all the images, or all the galleries which is useless.
You can even use a counter as you cycle through the array to try to count how many images are in your gallery, but you’ll still get the wrong number.
You can try to use the global variables tthere by default: images->total, which are empty and undefined and don’t even exist in the $images or $current object.
The code displays a (“Picture 3 of 7)” type display. If you use it in the imagebrowser.php template, it works. If you paste this exact same code in the gallery-carousel.php template. It will not work. Now you might think switching to $current->total would work, since it inexplicably does for the rest of the variables when using gallery_carousel, but no, it does not. The answer is you have to pull the info from the database directly.
It is a sinister, sinister plugin.
If you can’t count the images on a gallery, you can count the tags on html block.
On my theme, I get the gallery ID from an custom field and echo the gallery inside the template. So, it’s something like that:
Hope it helps.