Tweaking the NextGEN Gallery Plugin

Fair Warning: This one gets rather technical. But if a PHP Neophyte like me I can figure it out, anyone who has installed their own WordPress blog should be able to handle it.

After installing the NextGEN Gallery plugin to better manage photos on this blog, we discovered just one issue we didn’t like about it. Viewers could only see the first six (our image maximum number set in the preferences) photos at full size when clicking on a thumbnail even if there were multiple sub-pages of photos.

I found this quick fix in the NextGEN forums which requires editing the nggfunction.php file. I include the required code modifications below for your convenience, or confusion if that may be the case. Just be sure to make a backup copy of your nggfunction.php file first!

One more note of caution: For galleries with hundreds of photos, modifying the plugin this way may cause extra strain on the server when calling the page since all the thumbnails will load at that time.

DISCLAIMER: No promises here. I take no credit for this and accept no liability if it doesn’t work for you. It did for me.

Download as a text file: NextGEN Gallery Plugin Modifications

1. Add this new function: (Not sure if it matters where, I added it right after function nggShowGallery.)

/**********************************************************/

 

function createNoShows($noshows, $thumbcode){

 

$return = ”;

 

if (count($noshows) > 0) {

 

$return .= ‘<div style=”display: none;”>’;

 

foreach ($noshows as $pic) {

 

$folder_url = get_option (‘siteurl’).”/”.$pic->path.”/”;

 

$picturefile = nggallery::remove_umlauts($pic->filename);

 

$link =($ngg_options[‘galImgBrowser’]) ? htmlspecialchars(add_query_arg(array(‘page’=>get_the_ID(),’pid’=>$pic->pid))) : $folder_url.$picturefile;

 

$return .= ‘<a href=”‘.$link.'” title=”‘.stripslashes($pic->description).'” ‘.$thumbcode.’ ></a>’;

 

}
$return .= ‘</div>’.”\n”;
}
return $return;
}

 

2. In function nggCreateGallery find

 

array_splice($picturelist, 0, $start);

 

before this add:

 

$noshows_before = array_slice($picturelist, 0, $start);

 

3. In function nggCreateGallery find

array_splice($picturelist, $maxElement)

 

before this add:

 

$noshows_after = array_slice($picturelist, $maxElement);

 

4. In function nggCreateGallery find

 

foreach ($picturelist as $picture) {

 

before this add:

 

$out .= createNoShows($noshows_before, $thumbcode);

 

5. In function nggCreateGallery find

 

$out .= ($maxElement > 0) ? $navigation : ‘<div class=”ngg-clear”></div>’.”\n”;

 

before this add:

 

$out .= createNoShows($noshows_after, $thumbcode);

7 Responses to “Tweaking the NextGEN Gallery Plugin”

  1. After a late night last night, I figured out how to modify version 1.0.2. Here’s the discussion and instructions on the WordPress forum…

    http://wordpress.org/support/topic/228743

    Steve

  2. … this modification does not work with the latest version of the Nextgen Gallery (1.0.2) …

    Thanks for the warning!!! Another reason not to upgrade. 😉

  3. For what it’s worth, this modification does not work with the latest version of the Nextgen Gallery (1.0.2) of this post. It does work with v0.99 which I was using. Upgrading to the new version broke it and the newer code is way different.

    Steve

  4. Thanks for the help on this one. One small issue I found. I downloaded the text file, and in it, the last instruction requires that you put in:

    $out .= createNoShows($noshows_after, $thumbcode);

    The line should really be:

    $out .= createNoShows($noshows_after, $thumbcode);

    Without the tag. Looks like perhaps a cut and paste error?

  5. Great article. Hopefully I can get it to work with some of my galleries. I use this plugin all the time and some of the biggest issues I have comes with the display of the thumbnails.

    Also, I’ve spent some time working on getting the gallery to display in the header…as there was no clear tutorial on alex.rabe’s site about how to do it. You’ve helped me, now maybe I can help you. Here is the tutorial on implementing the NEXTGEN Gallery into the WordPress header.php file

Trackbacks/Pingbacks

  1. Free Wordpress.com vs. Custom Wordpress.org Blog Differences | live. work. dream. - February 26, 2009

    […] your own installation you can hack away to your heart’s content and tweak the code to customize functionality and appearance however you see fit. This does however, require […]

  2. Nextgen Gallery Image Navigation - December 28, 2008

    […] get it to do what I wanted. If you’re using that version, you can find those instructions here. Unfortuantely, they don’t work for the newest version (1.0.2) because of significant […]

Leave a Reply