• Resolved marianvlad

    (@marianvlad)


    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)
  • Right, What should be shown instead ?

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

    I will remove it from the drop down list… this would be easy. Thanks for the hint

    Thread Starter marianvlad

    (@marianvlad)

    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.

    Thread Starter marianvlad

    (@marianvlad)

    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.

    https://www.marianvlad.ro/2010/10/nextgen-gallery-image-user-level/

    Alex Rabe

    (@alexrabe)

    You can add a code change & feature request here :

    https://code.google.com/p/nextgen-gallery/

    BTW : Didn’t understand anything ??

    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!

    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

    (@khaledhakimgmailcom)

    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.

    You’re welcome, I’m happy it helped someone!

    Khaled Hakim

    (@khaledhakimgmailcom)

    ?? Cheers.

    @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 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!!

    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 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.