0

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
8
  • I remember using custom templates for NextGen, can you not just count() the images in the array?
    – Cristian
    Commented Nov 19, 2012 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
    Commented Nov 20, 2012 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
    Commented Nov 20, 2012 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
    Commented Nov 20, 2012 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
    Commented Nov 20, 2012 at 16:03

2 Answers 2

0

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 :)

0
0
if ( $postid !='' ) {
    $set = ci_featgal_get_attachments();
    $i = 0;
    while ( $set->have_posts() ) : $set->the_post();
        get_template_part( 'loop' ); 
        $i++;
    endwhile; 
    wp_reset_postdata(); 
    ?><h6 style="font-size:10px;color:#c9b07d;"><?php echo $i ." PHOTOS";?></h6><?php
}
1
  • Please file an edit and explain why this would work.
    – Gabriel
    Commented Sep 19, 2015 at 16:44

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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