[resolved] [closed] [Plugin: NextGEN Gallery] Is it possible to specify url links in thumbnails? (45 posts)

  1. Adam W. Warner
    Posted 7 years ago #

    I have searched for the answer to this, but all I've found here in the forums is the same question with no responses.

    I would like to use NextGEN Gallery to display thumbnails in various pages. The caveat is that I would like to be able to link these thumbnails to specified urls.

    Does anyone know a hack for this?

  2. shauno
    Posted 7 years ago #

    I have a way, but it is a hack, and kinda a self plug as it uses my plugin :)

    First thing you need to do is edit the NextGEN settings, to not do a javascript effect onclick. This is under the 'Gallery->Options->Effects' menu. Set the option 'JavaScript Thumbnail effect' to 'None'

    Now download and install NextGEN Custom Fields plugin (http://wordpress.org/extend/plugins/nextgen-gallery-custom-fields/). This will enable you to add custom fields to images in NextGEN. Once installed, create a new text input custom image field (I will use the name 'custom link' in this example, but you can call it what you want)

    Lastly, in the NextGEN gallery template file, you need to change link for the images. Look at the file 'gallery.php' in the '/nextgen-gallery/view/' directory and find where it loops through $images, and echos the link (line 42 on my copy). Change that line from <a href="<?php echo $image->imageURL ?>" title="<?php echo $image->description ?>" <?php echo $image->thumbcode ?> > to <a href="<?php echo $image->ngg_custom_fields["custom link"]; ?>" title="<?php echo $image->description ?>" <?php echo $image->thumbcode ?> > (notice the name of the custom field, change that to whatever you called yours)
    And that's it. Custom links for your images.

    Let me know how that works for you.

  3. Adam W. Warner
    Posted 7 years ago #

    @ shauno,


    This worked exactly as described. I've added this to my "list of hacks I've made" document I read before upgrading any plugins. I'm truly surprised that this feature isn't built into the NextGEN core, but maybe in the future a feature could be added to include any custom fields created with your plugin.

    Very great stuff shauno, thanks a ton!

  4. shauno
    Posted 7 years ago #

    No problem! Glad to help.

    And, you can upgrade NextGEN if you want. NextGEN uses templates to display the images. When you edited 'gallery.php', you didn't hack the plugin at all, you just changed the way it displays the data. You just need to note down that line of code you changed in the gallery.php template, and remember to change it again if you upgrade.

  5. brydave
    Posted 7 years ago #

    Hi Shauno,
    I was wondering if there is a way of applying this to smoothgallery?

    I have followed your directions here, but the images are still linking to themselves...

    Any suggestions would be really appreciated!
    Great Plugin by the way!

  6. shauno
    Posted 7 years ago #

    Hey brydave

    If you are referring to NextGEN Smooth Gallery, then I have good news! It is possible.
    But, it does require a little more 'hack' than before.

    The first problem, is that NextGEN Smooth Gallery doesn't seem to care about the unique image id, but we need it. So, to solve that you need to change line 102 of nggSmoothSharedFunctions.php from the blank line it is now, to this:
    $aux["pid"] = $picture->pid;

    Now, we can get the custom field created with NextGEN Custom Fields to use as the link like this:
    On line 182 of nggSmoothSharedFunctions.php (if you didn't create any new lines with the previous edit), you will see the <a> link code. You need to replace that line with this:
    $out .= " <a target=\"_blank\" href=\"" . nggcf_get_field($picture["pid"], "custom link") . "\" title=\"open image\" class=\"open\"></a>";

    Remember to use the name you called your custom field in the place of "custom link", as in the example I showed awarner20.

    That should be it, let me know how that works out for you :)

    [edit: fixed funky markup that broke this post, x2]

  7. brydave
    Posted 7 years ago #

    Thank you very much, it worked perfectly!
    Thats such a useful hack for smoothgallery.

    Thanks again!

  8. Adam W. Warner
    Posted 7 years ago #

    Hey there shauno,

    I just discovered that using your hack above works as expected if I enter [nggallery id=1] in to my page template, but when I add the image caption, [nggallery id=1 template=caption], the thumbnails no longer link to my custom links.

    Do you have any thoughts on this?

    I'm starting to dig around a bit and will post back if I find a solution.

  9. Adam W. Warner
    Posted 7 years ago #


    The same hack is needed in gallery-caption.php


  10. mpanda
    Posted 7 years ago #

    Thank you so much Shauno, it works flawless!

    I've a question: is it possible to choose to apply such an hack only to specific galleries in order to keep lightbox fx for other galleries where 'custom link' is not useful?

  11. ivanotls
    Posted 7 years ago #


    I posted a similar request : "[resolved] [Plugin: NextGEN Gallery] How-to use [ singlepic id=100] as an image for HREF"


    Looking at this post you will find the solution suggested by "andreask"
    With this solution we can explicitly specify a link when we need.

    Shauno, which is the tread-off of this approach ? what do u think about ?

    Best regards.

  12. shauno
    Posted 7 years ago #

    Hi ivanotls

    Both the solution in this thread, and the solution from andreask do mostly the same thing.

    The benefit of using the solution mentioned here, is that you don't 'hack' the code for NextGEN at all, so you can upgrade the plugin without losing your changes (with the exception of the template, but that's what they are for)

    Alex (the NextGEN author) was kind enough to put a bunch of hooks in his code for other plugins to add nifty features. So I say, why not use them?

  13. shauno
    Posted 6 years ago #

    Sorry mpanda, I missed your post for a couple days :)

    And yes, this hack can be done on only certain galleries, but it depends on how you are showing the galleries.

    If you are manually adding the [nggallery id=x] shortcode to display your galleries, then it is easy.

    Do everything I explained in my earlier post, up to the point where you need to edit gallery.php in the /nextgen-gallery/view/ directory. Instead of editing that file, create a copy called gallery-customlinks.php.
    Now instead of editing gallery.php as previously explained, edit gallery-customlinks.php that way.
    Now, for the galleries you want to use the custom links, call the code [nggallery id=x template=gallery-customlinks]

    I hope that makes sense to you. Basicly, NextGEN has template files to display galleries. If you don't specify what template file to use, the gallery picks the best one based on your settings. But, you can override that by specifying the template attribute in the shortcode.

    [Edit: Fixed a typo]

  14. mpanda
    Posted 6 years ago #

    Sorry Shauno for my delay as I missed your kindest reply as well.

    I still not test your tip yet but I'm sure it will works as logic code will remain the same.
    I'd have one more question about Nextgen seo optimization but it's a bit off topic so I'll address it to a new thread
    Thank you so much

  15. mpanda
    Posted 6 years ago #

    Hi Shauno, we saw how to apply this hack to galleries and pics.
    I wonder if it's possible to apply it to a slideshow as well.

  16. David Radovanovic
    Posted 6 years ago #


    I was this -><- close to make a horrible hack to my Nextgen Smoothgallery till I installed your Nextgen Custom Fields plugin and read your reply brydave. Like brydave I needed to control whether to link to a page or image using the NextGen SmoothGallery plugin. You made my day! Thanks for a very useful addition to NexGen that should be incorporated in its core.

  17. bengo-matus
    Posted 6 years ago #

  18. kpink33
    Posted 6 years ago #

    First of all thank you so much for these helpful links...I have just finished my site: kpstudioworks.com

    I used the custom fields to have a gallery where each image links to a different page. Each page that it links to has a gallery of images that when clicked on they will open up into a lightbox.

    The solution of creating a file called gallery-customlinks.php works very well.

    I just wanted to point out one important thing however, when you enter the shortcode it should read [nggallery id=x template=customlinks]

    A previous post had this written incorrectly as [nggallery id=x template=gallery-customlinks] <-writing it in this manner will not render the gallery properly

    Thanks Again I am greatful to how helpful this has been...please check out my site

  19. ndmeador
    Posted 6 years ago #

    Shauno, your instructions worked for viewing gallery images on NextGen's default Albums page. Now I'm trying to apply your guide to the related image thumbnails that NextGen can display below a single image in a post (I'm using tags to find them).

    The controls for nggShowRelatedGallery() start in nggfunctions.php at line 710. I replaced the imageURL with ngg_custom_fields["custom_link"] -- where custom_link is the name of my custom field. However, this only links the thumbnails to the URL that I'm currently viewing.

    This may be a more complicated hack than doing this for Gallery thumbnails. Thanks for your help! Here's my site: michiganradiopictureproject.org

  20. aminabbasian
    Posted 6 years ago #

    Just in response to have two galleries on a site issue - one with thickbox and the other with a custom template to open links in a new window.

    There are a couple of points that should be pointed out for this two work.

    Ensure that in "effects" you choose Thickbox. And in gallery-customlinks.php you need to delete the code <?php echo $image->thumbcode ?>. This takes away the class from the images and the links will then be able to work and also add target="_blank" so the links open in a new window.

    Hope this helps!

  21. enigma23
    Posted 6 years ago #

    I'm hurting big time. Trying to complete the Smooth Gallery mod. Ran through Shauno's description several times. All goes well until the nggsmoothsharedfunctions.php mod. After completing, I get a PARSE ERROR "unexpected T STRING".

    The two line numbers (102 & 182) described above, don't match with what I see in my editor, but I think I'm in the right spot. Can anyone help?

  22. shauno
    Posted 6 years ago #

    Hey enigma23
    The parse error will tell you which file and what line are giving the problems.
    Paste the code, from about 5 lines above the line number specified, to 5 lines after, and I will see if I can see what the problem is.

  23. jennyrrr
    Posted 6 years ago #

    Help Please!
    I have installed the custom field plugin, added a gallery called thumbnails, changed the code line 42 in gallery.php. added the shortcode [[nggallery id=x] and the gallery is showing up as thumbnails horizontally on home page - just what I wanted - although I now want to link each thumbnail to individual pages within my site. Where do I specify the link URL for each image - it doesn't appear to give me a custom field for each image. (Is that what this plug in should do?)

    Site URL is: readscreations.co.uk

    I would also like to add a caption under each thumbnail - saying More Info >>> - please can you explain how I do this.

    I have been looking for ways to do the above for ages and, hopefully, at last this will work for me.

    Your help would be appreciated.

  24. jennyrrr
    Posted 6 years ago #


    I have sorted it - just need to add the captions now.

    WordPress Custom Field Plugin is brilliant plug in, Ihave been looking for this for ages and it works really well.

    Thanks Shauno

  25. shauno
    Posted 6 years ago #

    Hey jennyrrr
    Glad you got it working, and glad you like the plugin!

  26. lwatkins
    Posted 6 years ago #

    Sorry, but I posted this on a resolved post. Here is the correct unresolved post:


  27. ribbu
    Posted 6 years ago #

    Hi there -
    After lots of searching, found this post - THANK YOU! Wondering how to make the link appear in a pop-up window, though...?

  28. shauno
    Posted 6 years ago #

    The thread that wouldn't die :)

    I suppose you could just add target="_blank" to the hrefs. Simple, but affective.

  29. BakingandBooks
    Posted 6 years ago #

    Shauno thank you for sharing your time and expertise on this thread!

    I have implemented all the suggestions you made but still the thumbnails are linking to the post preview page. I disabled the JS effects, installed the Next Gen custom fields plugin and edited line 42 of gallery.php and gallery-caption.php. Still no luck though - the gallery displays as if I hadn't made any changes at all, with thumbnails linking to post preview page. I'm using [nggallery id=1 template=caption] to call my gallery.

    Any ideas why this isn't working? It seems so straight forward!

  30. BakingandBooks
    Posted 6 years ago #

    Nevermind, it appears to be working now! For some reason the urls weren't being saved when I added them to the custom field. It's all good now. Thanks!!

Topic Closed

This topic has been closed to new replies.

About this Topic