phpwordpressnextgen-gallery

Wordpress NextGen Gallery - Only show if gallery has images


I have created 4 empty galleries(using Nextgen) and I have one list of static image links. The empty galleries have been created so that if someone wants to add images in them later, that gallery will show up in place of the static image links.

The static image links should up if no images are in the Nextgen gallery, but if there are images in the NextGen gallery - use those in place of the static image links.

This is the code I am using for the Nextgen gallery that I'm calling in the page template:

<?php global $nggdb;
$gallery = $nggdb->get_gallery(1, 'sortorder', 'ASC', true, 0, 0);
foreach($gallery as $image) {
echo '<img src="';
echo $image->imageURL;
echo '" />';
}
?>

I know I need to check to see if the specified gallery has images, and then if not, do an else statement, but I'm not exactly sure how to do this.

Any help is greatly appreciated. Thank you.


Solution

  • You could try something like this:

    $gallery = $nggdb->get_gallery(1, 'sortorder', 'ASC', true, 0, 0);
    if ( !empty($gallery) && is_array($gallery) && count(gallery) > 0 ) {
       foreach($gallery as $image) { ... }
    } else {
       //show static image links
    }