Title: [Plugin: NextGEN Gallery] Nextgen Gallery exclude bug
Last modified: August 19, 2016

---

# [Plugin: NextGEN Gallery] Nextgen Gallery exclude bug

 *  Resolved [marianvlad](https://wordpress.org/support/users/marianvlad/)
 * (@marianvlad)
 * [15 years, 8 months ago](https://wordpress.org/support/topic/plugin-nextgen-gallery-nextgen-gallery-exclude-bug/)
 * I want to report a small bug for NextGen Gallery.
    For each image of a gallery
   there is the option “exclude”, which means that the image does not appear anywhere.
   But it still appears in the preview of an album if it was set as “Preview image”
   in the “Gallery settings”.

Viewing 14 replies - 1 through 14 (of 14 total)

 *  [Alex Rabe](https://wordpress.org/support/users/alexrabe/)
 * (@alexrabe)
 * [15 years, 8 months ago](https://wordpress.org/support/topic/plugin-nextgen-gallery-nextgen-gallery-exclude-bug/#post-1716809)
 * Right, What should be shown instead ?
 *  [mr_swede](https://wordpress.org/support/users/mr_swede/)
 * (@mr_swede)
 * [15 years, 8 months ago](https://wordpress.org/support/topic/plugin-nextgen-gallery-nextgen-gallery-exclude-bug/#post-1716848)
 * Alex,
 * I guess it would be best if the excluded image is not available in the “Preview
   image” drop down menu thereby resulting in a random image to be shown instead
   which is default.
 * Excluding an image that is selected as gallery preview image could also result
   in a warning…but that might be a too sophisticated solution since I guess you
   have enough to consider already…:)
 *  [Alex Rabe](https://wordpress.org/support/users/alexrabe/)
 * (@alexrabe)
 * [15 years, 8 months ago](https://wordpress.org/support/topic/plugin-nextgen-gallery-nextgen-gallery-exclude-bug/#post-1716886)
 * I will remove it from the drop down list… this would be easy. Thanks for the 
   hint
 *  Thread Starter [marianvlad](https://wordpress.org/support/users/marianvlad/)
 * (@marianvlad)
 * [15 years, 8 months ago](https://wordpress.org/support/topic/plugin-nextgen-gallery-nextgen-gallery-exclude-bug/#post-1716906)
 * Alex,
 * i solved this little bug through a less professional way (because i’m not an 
   programmer). Ideally, it could be resolved by a java script to populate the drop
   down list as soon as they change a rule checkbox.
    For temporal resolution could
   be replaced:
 *     ```
       if ( is_array($pictures) ){
                               foreach( $pictures as $pid ){
                                       $pid = (int) $pid;
                                       if (is_array($exclude)){
                                               if ( array_key_exists($pid, $exclude) )
                                                       $wpdb->query("UPDATE $wpdb->nggpictures SET exclude = 1 WHERE pid = '$pid'");
                                               else
                                                       $wpdb->query("UPDATE $wpdb->nggpictures SET exclude = 0 WHERE pid = '$pid'");
                                       } else {
                                               $wpdb->query("UPDATE $wpdb->nggpictures SET exclude = 0 WHERE pid = '$pid'");
                                       }
                               }
                                              }
       ```
   
 * with:
 *     ```
       if ( is_array($pictures) ){
                               foreach( $pictures as $pid ){
                                       $pid = (int) $pid;
                                       if (is_array($exclude)){
                                               if ( array_key_exists($pid, $exclude) )
                                                       $wpdb->query("UPDATE $wpdb->nggpictures SET exclude = 1 WHERE pid = '$pid'");
                                               else
                                                       $wpdb->query("UPDATE $wpdb->nggpictures SET exclude = 0 WHERE pid = '$pid'");
                                       } else {
                                               $wpdb->query("UPDATE $wpdb->nggpictures SET exclude = 0 WHERE pid = '$pid'");
                                       }
                               }
                               $last_exclude_key=array_pop(array_keys($exclude));
                               for ($new_preview_image_id=1; $new_preview_image_id<=$last_exclude_key+1; $new_preview_image_id++){
                                   if (!array_key_exists($new_preview_image_id, $exclude)){
                                       $wpdb->query("UPDATE $wpdb->nggallery SET previewpic=".$new_preview_image_id." WHERE gid=".$_GET['gid']."");
                                       break;
                                   }
                               }
                       }
       ```
   
 * in /admin/manage.php file.
 * This piece of code will replace the “preview image” thumbnail with the first 
   image that is not excluded.
 *  [Alex Rabe](https://wordpress.org/support/users/alexrabe/)
 * (@alexrabe)
 * [15 years, 8 months ago](https://wordpress.org/support/topic/plugin-nextgen-gallery-nextgen-gallery-exclude-bug/#post-1716938)
 * Fixed for next release :
 * [http://code.google.com/p/nextgen-gallery/source/detail?r=836](http://code.google.com/p/nextgen-gallery/source/detail?r=836)
 *  Thread Starter [marianvlad](https://wordpress.org/support/users/marianvlad/)
 * (@marianvlad)
 * [15 years, 7 months ago](https://wordpress.org/support/topic/plugin-nextgen-gallery-nextgen-gallery-exclude-bug/#post-1716966)
 * Thanks Alex.
 * Please “drop” a look at the link below and tell me if in future you will also
   consider this option which I think more than necessary.
    Tell me if the Google
   AJAX Translation not help to post in English.
 * [http://www.marianvlad.ro/2010/10/nextgen-gallery-image-user-level/](http://www.marianvlad.ro/2010/10/nextgen-gallery-image-user-level/)
 *  [Alex Rabe](https://wordpress.org/support/users/alexrabe/)
 * (@alexrabe)
 * [15 years, 7 months ago](https://wordpress.org/support/topic/plugin-nextgen-gallery-nextgen-gallery-exclude-bug/#post-1716969)
 * You can add a code change & feature request here :
 * [http://code.google.com/p/nextgen-gallery/](http://code.google.com/p/nextgen-gallery/)
 * BTW : Didn’t understand anything 🙂
 *  [Sprutt](https://wordpress.org/support/users/sprutt/)
 * (@sprutt)
 * [15 years, 5 months ago](https://wordpress.org/support/topic/plugin-nextgen-gallery-nextgen-gallery-exclude-bug/#post-1716997)
 * Hi,
 * I’m wondering if there is a somewhat simple way for me to revert this change?
 * What I’m aiming at doing is having separate size thumbnails in my album from 
   what I have in my galleries. The only way I can see to achieve this is to have
   one image with a differently sized thumbnail, which I use for the album, and 
   that I hide from showing up in my gallery.
 * Or is there another way around this?
 * Thanks for a great plugin and for any help on this!
 *  [Sprutt](https://wordpress.org/support/users/sprutt/)
 * (@sprutt)
 * [15 years, 5 months ago](https://wordpress.org/support/topic/plugin-nextgen-gallery-nextgen-gallery-exclude-bug/#post-1716998)
 * Figured it out if someone’s in need of this functionality.
 * To show the excluded images of a gallery in the “Preview image” dropdown, just
   go into manage-images.php and comment out line 275, which is holding the conditional
   statement for this. It looks like so:
 * `if ($picture->exclude) continue;`
 *  [Khaled Hakim](https://wordpress.org/support/users/khaledhakimgmailcom/)
 * (@khaledhakimgmailcom)
 * [15 years, 1 month ago](https://wordpress.org/support/topic/plugin-nextgen-gallery-nextgen-gallery-exclude-bug/#post-1717026)
 * **Sprutt**… you saved my life. 🙂 Appreciated… I was looking for way to undo 
   what has been done (showing excluded images as preview images for a gallery)…
   and I was about to lose hope when I stumbled across this.
 * Great stuff… Appreciate your sharing that wish us! Much respect.
 *  [Sprutt](https://wordpress.org/support/users/sprutt/)
 * (@sprutt)
 * [15 years, 1 month ago](https://wordpress.org/support/topic/plugin-nextgen-gallery-nextgen-gallery-exclude-bug/#post-1717027)
 * You’re welcome, I’m happy it helped someone!
 *  [Khaled Hakim](https://wordpress.org/support/users/khaledhakimgmailcom/)
 * (@khaledhakimgmailcom)
 * [15 years, 1 month ago](https://wordpress.org/support/topic/plugin-nextgen-gallery-nextgen-gallery-exclude-bug/#post-1717028)
 * **😉 Cheers.**
 *  [Zoinks! Graphics](https://wordpress.org/support/users/zoinks/)
 * (@zoinks)
 * [14 years, 10 months ago](https://wordpress.org/support/topic/plugin-nextgen-gallery-nextgen-gallery-exclude-bug/#post-1717041)
 * [@sprutt](https://wordpress.org/support/users/sprutt/) Consider that at least
   2 someones you helped. Your hack is just what I was looking for! Kind of begs
   the question: Is there a way to maintain this plugin hack when a new update to
   NGG comes out?
 * ———————-
 * [@alex](https://wordpress.org/support/users/alex/) I feel for you, man, I really
   do. Seems like half the people on here discussing this issue want the ability
   to select an excluded image for the Preview Image, and the other half get freaked
   out if an excluded image appears in the Preview Image dropdown, so no matter 
   what you do you can’t win for trying!
 * Well, how’s this for a solution: Can the “if ($picture->exclude) continue;” code
   that Sprutt points out above be conditional, based on a selection made in the“
   Gallery / Options”? That way it gives the user the ability to choose which way
   works best for them.
 * Personally, I’m of the mind that I’d like to have the ability to select a Preview
   Image that doesn’t show up in the Gallery, and being able to select an excluded
   one would be ideal. So if you could work this into the next update, that would
   be super-cool! Oh yeah, and thanks again Alex for all the work you do on this
   plugin!!
 *  [Zoinks! Graphics](https://wordpress.org/support/users/zoinks/)
 * (@zoinks)
 * [14 years, 10 months ago](https://wordpress.org/support/topic/plugin-nextgen-gallery-nextgen-gallery-exclude-bug/#post-1717042)
 * Okay, here’s an alternative solution that doesn’t require Alex to add anything
   to the NextGen code *AND* will survive NGG plugin updates. It’s an alteration
   of the gallery.php code so there’s no need to exclude the Preview Image or alter
   the NextGen core code to force a display of excluded images in the first place.
   Neat huh??
 * 1. Replace the standard NextGen gallery presentation with a custom one in your
   theme by copying the “/wp-content/plugins/nextgen-gallery/view/gallery.php” file
   to “/wp-content/themes/your-theme/nggallery/gallery.php” (You may have to create
   the “nggallery” folder in your theme.)
 * 2. Now I really customized my gallery, so a lot of the standard code has been
   removed & changed around in what’s below. The important bits are the lines between“
   if(!empty($gallery))” and “foreach($images as $image)” as well as the “if($PreviewImgPath
   ==$image->imageURL) { continue; }” line…
 *     ```
       if(!empty($gallery))
       	{
       	global $wpdb;
   
       	$results = $wpdb->get_results("SELECT ng.path, np.filename FROM wp_ngg_pictures np, wp_ngg_gallery ng WHERE np.galleryid=ng.gid AND np.galleryid=" . $gallery->ID . " AND np.pid=ng.previewpic",ARRAY_A);
   
       	if(!empty($results[0]['path']) && !empty($results[0]['filename']))
       		{ $PreviewImgPath = get_bloginfo('url') . '/' . $results[0]['path'] . '/' . $results[0]['filename']; }
   
       	foreach($images as $image)
       		{
       		if($PreviewImgPath==$image->imageURL) { continue; }
   
       		if($image->hidden) { continue; }
   
       		$ImageCode .= '<div style="float:left; padding:5px;">' .
   
       			'<a href="' . $image->imageURL . '" title="' . $image->description .
       			'" ' . $image->thumbcode . '>' . '<img title="' . $image->alttext .
       			'" alt="' . $image->alttext . '" src="' . $image->thumbnailURL .
       			'" ' . $image->size . ' /></a>' .
   
       		'</div>';
       		}
   
       	if($pagination)
       		{ $pagination = '<br style="clear:both;" />' . $pagination; }
   
       	echo '<div id="galLery2">' . $ImageCode . $pagination . '</div>';
       	}
       ```
   
 * The code above basically tells the gallery to display everything *BUT* the Preview
   Image. This is done via a wpdb query to get the gallery’s Preview Image URL, 
   comparing that to each image in the $gallery array, then skipping over the image
   if the URLs match.
 * Granted, the wpdb query is a bit kludgy, but it’s the only way I could figure
   to get the Preview Image info from the gallery.php page. And I looked **A LOT**.
   Thanks to [GitHub:Gist](https://gist.github.com/999520) for getting me started
   in that direction. However, if anyone has any cleaner way of doing so, I’m happy
   to hear. Otherwise, hope this helps!

Viewing 14 replies - 1 through 14 (of 14 total)

The topic ‘[Plugin: NextGEN Gallery] Nextgen Gallery exclude bug’ is closed to new
replies.

 * ![](https://ps.w.org/nextgen-gallery/assets/icon-256x256.png?rev=2083961)
 * [Photo Gallery, Sliders, Proofing and Themes - NextGEN Gallery](https://wordpress.org/plugins/nextgen-gallery/)
 * [Frequently Asked Questions](https://wordpress.org/plugins/nextgen-gallery/#faq)
 * [Support Threads](https://wordpress.org/support/plugin/nextgen-gallery/)
 * [Active Topics](https://wordpress.org/support/plugin/nextgen-gallery/active/)
 * [Unresolved Topics](https://wordpress.org/support/plugin/nextgen-gallery/unresolved/)
 * [Reviews](https://wordpress.org/support/plugin/nextgen-gallery/reviews/)

## Tags

 * [exclude](https://wordpress.org/support/topic-tag/exclude/)

 * 14 replies
 * 6 participants
 * Last reply from: [Zoinks! Graphics](https://wordpress.org/support/users/zoinks/)
 * Last activity: [14 years, 10 months ago](https://wordpress.org/support/topic/plugin-nextgen-gallery-nextgen-gallery-exclude-bug/#post-1717042)
 * Status: resolved