Individual Facebook Like Buttons for Images with NextGEN Gallery
Because I think this is probably of interest to some people but I don’t have a lot of ambition to write about it, I will present these instructions as concisely as possible:
- Have a WordPress website up and running
- Install the NextGen Gallery plugin
- Install FancyBox the old fashioned way or as a plugin
- Read this post about Facebook Open Graph WordPress Integration to learn about adding proper Open Graph meta elements to the header of your site.
- From your WordPress admin pages go to Gallery > Options > Effects
- Link code line: rel=”gallery”
- Then go to Gallery > Options > General Options
- Activate Permalinks: YES and define a slug.
- Then go to Gallery > Options > Gallery
- Show ImageBrowser: YES
The trick with getting NextGEN Gallery to both display your image galleries large images as FancyBox overlays and create unique pages with URLs to display each individual image is to enable the ImageBrowser mode but then alter NextGEN Gallery.php template so that the FancyBox (or other overlay solution) code is used regardless of the “Show ImageBrowser” setting.
With the above settings in place, backup a copy of the NextGEN gallery plugin files from your web server.
Then navigate to following file and open it with your favorite text editor.
[YourDesktop or wherever]/nextgen-gallery/view/gallery.php
Scroll down to the part where it says “Thumbnails” in comments. This is the loop that outputs the thumbnail grid that displays your embedded NGG gallery on the page. Find the line below:
<a href="<?php echo $image->imageURL ?>" title="<?php echo $image->description ?>" <?php echo $image->thumbcode ?> >
and change it to:
<a href="<?php echo $image->imageURL ?>" title="<div style="float:left; width:70px;"><iframe src="http://www.facebook.com/plugins/like.php? app_id=YOUAPPIDNUMBERHERE&amp;href=<?php echo urlencode(get_permalink()) ?>%2F YOURGALLERYSLUGHERE%2Fimage%2F<?php echo urlencode($image->image_slug) ?>&amp; send=false&amp;layout=box_count&amp;width=50&amp;show_faces=true&amp; action=like&amp;colorscheme=light&amp;font&amp;height=60" scrolling= "no" frameborder="0" style="border:none; overflow:hidden; width:70px; height:60px;" allowTransparency="true"></iframe> </div>" <?php echo $image->thumbcode ?> rel="gallery">
Save gallery.php and upload to your webserver. If you have the OpenGraph meta elements in place you should now be able to navigate to a NextGEN Gallery on your site, click on a thumbnail and see something like this (right):
This is an individual Like button, allowing your visitors to “Like” specific images within a gallery. Now, it doesn’t work perfectly. Even though you are linking the Like button to a URL that is specific to that image, in my experience Facebook still grabs the first image from that gallery for the thumbnail displayed on the individual’s Facebook Wall. And it seems like the link from Facebook will take visitors to the gallery page of the specific image. Again, this is odd and shouldn’t be, but Facebook is doing a lot of magic here, so who knows why it isn’t working perfectly. The important thing is:
- Your visitors can Like individual images.
- If visitors see a link to your image on Facebook, clicking the link will take them to the gallery that contains the image in question.
If you get this successfully working to fulfill your needs, be sure to keep a backup of your gallery.php file. Every time the NextGen Gallery plugin is updated this file will most likely get overwritten.