Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

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:

<?php 
global $wpdb; 
$images = intval( $wpdb->get_var("SELECT COUNT(*) FROM $wpdb->nggpictures") ); ?> 
<a rel="prettyPhoto" href="<?php echo $image->imageURL ?>" <?php $image->thumbcode ?>>
    <span>view</span>
</a>
<?php echo $images; ?> pictures
share|improve this question
    
I remember using custom templates for NextGen, can you not just count() the images in the array? –  Cristian Nov 19 '12 at 17:43
    
Hello Christian, Yes, I am using a custom template for the gallery. I just can't get each gallery displayed with the code above to display it for each array. Advice? –  Ian McAbee Nov 20 '12 at 6:10
    
Do you want a single page with a link to each gallery? If so I would suggest using the Album feature, as I think that's exactly what you want. –  Cristian Nov 20 '12 at 11:29
    
Yeah, I like the album feature and how it counts the number of galleries. I just need that sort of function for images per gallery. So it would print the number of images in a gallery. –  Ian McAbee Nov 20 '12 at 14:31
    
If you are outputting a gallery then there is a global called $images just use echo count( $images ). However if you are listing all galleries without being in an albumn and want to show the number of images I will have to do some more digging. –  Cristian Nov 20 '12 at 16:03
show 3 more comments

1 Answer

up vote 0 down vote accepted

Using your above code, you were just missing the WHERE clause. Hopefully that should work.

<?php 
global $wpdb; 
$images = intval( $wpdb->get_var("SELECT COUNT(*) FROM $wpdb->nggpictures WHERE galleryid = {$gallery->ID}") ); ?> 
<a rel="prettyPhoto" href="<?php echo $image->imageURL ?>" <?php $image->thumbcode ?>>
    <span>view</span>
</a>
<?php echo $images; ?> pictures

It's not the best way to implement it, but if it works for you :)

share|improve this answer
    
Cristian you are a saint, thank you sir! –  Ian McAbee Nov 27 '12 at 4:34
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.