Plymouth Design Group, LLC

10 Mar, 2011

Adding hyperlinks to NextGen Gallery MonoSlideshow

Posted by: chris In: Projects

We use the NextGEN Gallery plugin for WordPress on several sites and recently looked at extending it to work with MonoSlideshow. So we installed the NextGEN – MonoSlideshow plugin. One thing missing from this latter plugin is the ability to create hyperlinks for each of the images in the gallery that MonoSlideshow presents. The NextGEN Gallery Custom Fields plugin gets you a bit closer but not all the way there – it allows you to create the field for the hyperlink but you will need to do a bit more to pull all the pieces together.

The final step involves a bit of modification to the xml.php file within the NextGEN – MonoSlideshow plugin. See the modified code below. First add the followImageLinks=’true’ attribute in the album configuration on line 43. Create a variable for your link as we have in line 62 which calls the custom field for your hyperlink that you created within the Custom Fields plugin using the nggcf_get_field function. Finally, add your link to the returned array in line 66.

Here is the complete modified xml.php file:

<?php
 
if(preg_match('#' . basename(__FILE__) . '#', $_SERVER['PHP_SELF'])) { die('You are not allowed to call this page directly.'); }
 
global $wpdb;
 
$ngg_options  = get_option ('ngg_options');
$options      = get_option ('monoslideshow');
$siteurl      = get_option ('siteurl');
 
// get the gallery id
$galleryID = (int) $_GET['gid'];
 
// check if someone send the preset value
$preset = ( isset($_GET['preset']) ) ? $_GET['preset'] : '';
 
// get the pictures
if ($galleryID == 0) {
	$pictures = $wpdb->get_results("SELECT t.*, tt.* FROM $wpdb->nggallery AS t INNER JOIN $wpdb->nggpictures AS tt ON t.gid = tt.galleryid WHERE tt.exclude != 1 ORDER BY tt.{$ngg_options['galSort']} {$ngg_options['galSortDir']} ");
} else {
	$pictures = $wpdb->get_results("SELECT t.*, tt.* FROM $wpdb->nggallery AS t INNER JOIN $wpdb->nggpictures AS tt ON t.gid = tt.galleryid WHERE t.gid = '$galleryID' AND tt.exclude != 1 ORDER BY tt.{$ngg_options['galSort']} {$ngg_options['galSortDir']} ");
}
// read some default options
$delay = (int) $options['delay'];
$randomize = ($options['randomize']) ? 'true' : 'false';
$scaleMode = $options['scaleMode'];
$kenBurnsMode = $options['kenBurnsMode'];
$onAlbumEnd = $options['onAlbumEnd'];
$controls = ($options['controls']) ? 'normal' : 'none';
$backgroundColor = ($options['bgTransparent'] == true) ? 'transparent' : '#' . $options['backgroundColor'];
$displayMode  = $options['displayMode'];
$config = false;
 
//look for a preset file
if ( !empty($preset) )
    $config =  nggMonoslideshow::read_preset( $preset );
 
// Create XML output
header('Content-Type: text/xml; charset=' . get_option('blog_charset'), true);
echo '<?xml version="1.0" encoding="' . get_option('blog_charset') . '"?'.'>';
echo "<album>\n";
if ($config === false) {
echo "\t<configuration followImageLinks='true' onAlbumEnd='$onAlbumEnd' fullScreenScaleMode='$scaleMode' scaleMode='$scaleMode' backgroundColor='$backgroundColor' delay='$delay' randomize='$randomize'>\n";echo "\t\t<caption displayMode='$displayMode' />\n";
echo "\t\t<controller type='$controls' />\n";
echo "\t\t<transition kenBurnsMode='$kenBurnsMode' />\n";
echo "\t</configuration>\n";
} else
echo "\t$config\n";
echo "\t<contents>\n";
 
if (is_array ($pictures)){
	foreach ($pictures as $picture) {
 
        $description = htmlspecialchars ( strip_tags( stripslashes( nggGallery::i18n($picture->description) ) ) , ENT_QUOTES );
 
        if (!empty($picture->alttext))
            $title = stripslashes( htmlspecialchars (nggGallery::i18n($picture->alttext) , ENT_QUOTES) );
        else
            $title = $picture->filename;
 
        $link = nggcf_get_field($picture->pid, 'ImageLinksTo');        $path = $siteurl . '/' . $picture->path . '/' . $picture->filename;
        $thumbnail = $siteurl . '/' . $picture->path . '/thumbs/thumbs_' . $picture->filename;   
 
        echo "\t\t<image id='$picture->pid' source='$path' title='$title' link='$link' description='$description' thumbnail='$thumbnail' />\n";	}
}
 
echo "	</contents>\n";
echo "</album>\n";
 
?>

 

Step-by-step Instructions

 

1. Install the NextGen Gallery plugin.  Create a gallery.

2. Install the NextGen – MonoSlideshow plugin.

3.  Install the NextGEN Gallery Custom Fields plugin

4.  Add a custom field to the NGG Custom Fields plugin.  Click on NGG Custom Fields > Image Custom Fields.  Add a field called ImageLinksTo.  Check the checkbox to include the field in your gallery or galleries.  Field type is text input.

 

 

 

 

 

 

5.  Replace the [wordpress dir]/wp-content/plugins/nextgen-monoslideshow/xml.php file contents with the code that we provide above.  Upload via FTP.

6.  Go back to your NGG custom gallery and edit it.  Add URLs to your ImageLinksTo field.  See graphic.

 

 

 

 

 

 

7.  Done.  Refresh page and view gallery with clickable images.

 

 

 

14 Responses to "Adding hyperlinks to NextGen Gallery MonoSlideshow"

1 | Pamela

May 22nd, 2011 at 2:57 pm

Avatar

Hi there… I have been trying for 6 hours to incorporate links into monoslideshow using NEXTgen gallery on WordPress. I’ve been trying to do this via the monoslideshow.xml file. It’s obviously not working!

I have looked everywhere for the xml.php file that you mention above and cannot find it. I am using monoslideshow v.2. Can you please tell me where I would find this file?

Thanks so much for sharing your solution!

2 | admin

May 22nd, 2011 at 3:12 pm

Avatar

Pamela

Make sure you have all the necessary plugins/components as outlined in the article.

The xml.php is located in the [wordpress dir]/wp-content/plugins/nextgen-monoslideshow folder

3 | Stefan

July 2nd, 2011 at 1:12 pm

Avatar

Hey There,

I don´t know what I exactly have to do with the NextGEN Custom Fields after the installation.

Please help

4 | admin

July 3rd, 2011 at 3:22 pm

Avatar

Stefan,

The NGG Custom Fields Plugin has a documentation page here: http://wordpress.org/extend/plugins/nextgen-gallery-custom-fields/faq/

We are glad to help but you will need to be more specific

5 | Stefan

July 4th, 2011 at 8:08 am

Avatar

Hey Admin,

thanks for help.

I was adding a new Custum-Field with the url as the name.
And linked it in one of the galeries. But that´s not enough.

Did I have to displaying the nextgen-custom-fields with an php-tag to link the Monoslideshow?

6 | Stefan

July 4th, 2011 at 5:53 pm

Avatar

Ok,

now I understand more.
I did that: http://www.kimwoodbridge.com/nextgen-custom-fields-plugin-add-more-information-about-an-image-in-the-nextgen-gallery/

But “ImageLinksTo” as Field Name doesn´t work.

7 | admin

July 6th, 2011 at 11:47 am

Avatar

Did you replace the [wordpress dir]/wp-content/plugins/nextgen-monoslideshow/xml.php file with the code on our site?

I just retested our method with the latest release of the NGG plugin. It all still works correctly.

8 | admin

July 6th, 2011 at 12:10 pm

Avatar

I added some further information to our web page that may help you.

9 | Stefan

July 7th, 2011 at 8:28 am

Avatar

Hey admin,

with your step-by-step description I must changed the: “Field type” from “Area” in “Input” with the NGG Custom Fields plugin.

But it doesn´t work already.
Maybe it´s on the newsflash.xml-file in …/nextgen-monoslideshow/presets

Thx

11 | admin

July 7th, 2011 at 11:21 am

Avatar

No, if there is a problem with the preset xml file, then you will get a error message and your photos will not display. There is nothing in the preset file that needs to be changed using our method ( I briefly glanced at the Kim Woodbridge article that you mentioned – it seems that Kim offers a different way of achieving the clickable link)

At this point, the only realistic way to debug this is to review your actual code.

Chris Woods
Plymouth Design

12 | jason nelson

July 20th, 2011 at 10:36 am

Avatar

Your solution works great on the default preset for monoslideshow, but when I select one of the presets (like newsflash) or a custom one, then the links no longer work. Only when I have the default preset set to
‘none” does it work. Is there some code I need to add/adjust to the XML file?

13 | admin

August 1st, 2011 at 11:05 am

Avatar

Jason,

Yes, I was able to replicate that problem. Have not had time recently to dig into the code for a solution.

Chris

14 | jason nelson

August 2nd, 2011 at 9:47 am

Avatar

Thanks Chris, let me know if you’re able to come up with something. I’m assuming something in the default slideshow settings is different than the presets, but don’t know where to start looking or testing for it. I guessing the default settings are buried in a PHP file as I didn’t see an XML file for them.

Comment Form


  • angela: Very helpful article. Can you please let me know how to translate VBA sheet and workbook module code to XLM? I understand that by naming a macro Auto_
  • jason nelson: Thanks Chris, let me know if you're able to come up with something. I'm assuming something in the default slideshow settings is different than the pr
  • admin: Jason, Yes, I was able to replicate that problem. Have not had time recently to dig into the code for a solution. Chris