Mar 16, 2010

How to Integrate SlideShowPro Photo Galleries with ExpressionEngine

We’ve spent a good deal of time figuring out our current solution for integrating SlideShowPro (SSP) flash photo galleries with our favorite content management system ExpressionEngine (EE). If you are not already familiar with SlideShowPro, it is a Flash photo gallery component that reads XML files containing the list of images to display, with options such as transition effects, full screen mode, navigation styles and many others.

In this solution, a single EE weblog entry (not in the photo gallery module) is used for each photo. One Flash file is used to generate multiply galleries, and these galleries are created based on photos with matching categories or content within an EE field, such as an event name or tag.

How It Works

Before going through the steps, here’s the basic idea. The end result allows you to insert the following code in a template or entry to generate a gallery of photos that share the same EE category:

  • That embeds the flash gallery and passes a category variable.
  • The flash code grabs the category variable and calls an EE XML template.
  • The XML template uses that category to generate a list of photos within the category.
  • The SWF file reads the newly generated XML and displays the photos.
  • We’ll then modify this to generate a gallery based on matching field content.

Please note that while this method uses SlideShowPro, it could be modified to work with a non-flash HTML5/CSS3 gallery, and we’ll be working on that next.

How To Do It

Step 1: Create Your Flash File

Create a flash file and insert the SlideShowPro component on the stage. Click on the component on your stage and give it an instance name; we will use “ssp” for this tutorial. While the default method of calling an XML file is by putting the path in the component inspector, instead we will use some ActionScript to call an XML file (which will actually be an EE template) from the flash embed code.

In the first frame of a blank layer in Flash, insert the following ActionScript. Note the use of “ssp” referring to your instance name of SlideShowPro:

Export your flash file and upload the SWF to your server. We’ll come back to it later.

Step 2: Create a Flash Embed Template

First, we’ll look at the method for creating a gallery of photos that share the same category.

In EE, create a template that will contain your flash embed code, avoiding the need to always include the full flash embed code in a template or entry. For this tutorial, we’ll create an EE template group called “photos” and name this particular template “category.” In template preferences, choose “Yes” under “Allow PHP?” and “Input” under “PHP Parsing Stage.” In the template, use your favorite method of embedding a Flash file (several options are available in the SSP documentation) and reference the SWF you uploaded in step 1. We’ll add a couple of modifications from there.

Add the following PHP code to the top of your template:

Then, we need to add the flashvar to the Flash embed to call the XML template (that we’ll create in step 3) and pass the variable again. Depending on your method of embedding the flash, this exact code may differ, but the var is the same:

So, with those two code snippets, we first embedded the variable “cat” and named it “cat_num,” and then passed it to the XML and renamed it “cat” again. You can use any variable names you like.

Step 3: Create the XML Template

Within your new “photos” template group, create a template (of type “XML”) named “xml_category.” This is the template we called in step 2. Again, choose “Yes” under “Allow PHP?” and “Input” under “PHP Parsing Stage” in the template preferences.

Insert the following code in the template:

So in the top of this template we have the PHP and EE code to grab the variable. We request “cat” from step 2, and assign it the name “cat_value.” We then use a standard EE “assign_variable” tag to take “cat_value” and assign it the name “cat_num.”

Following that code are the opening “gallery” and “album” tags for the SSP XML. Your id, title, and description can vary.

Then we have the EE code that generates the list of photos. In the opening weblog:entries tag, we call the weblog “photos” (which you’ll create next) and for the category, our variable “cat_num.” You can use any additional parameters in the opening tag, such as orderby, sort, limit, etc to define what is displayed in the photo gallery.

Following that is our img tag, that will repeat for each photo within the category. Here, we are using the EE ImageSizer plugin to generate the small and full screen versions for the Flash, but you could replace this with standard image tags, as long as you keep the “photo_path” EE field as the image source.

Using ImageSizer, we are generating a 500 pixel version for the standard gallery and a 1024 version for the full screen gallery. We are then adding a photo caption, link to a detail page so you can have permalinks for photos, and a target for that link, which are all optional. Finally, we close the weblog:entries, album and gallery tags.

Step 4: Create the Weblog

Now we need a weblog and some entries so we have photos for the gallery. Create a weblog named “photos” and the custom fields we referenced in the XML template. These were “photo_path” and the optional “photo_caption.” Also create a field for an event title or keyword (we’ll call it “photo_event”) if you want to modify this method later to create a gallery based on field content. Finally, create some categories and assign them to the weblog.

Now, you can publish some entries within the photos weblog. In the photo_path field, include the path only (not a full image tag) to your image when using the photo upload tool. Make sure to create at least a few entries with the same category applied to test this method.

Step 5: Create a Gallery

We can now embed our flash in a template or entry to generate a gallery. Use the code we first looked at in the intro of this tutorial:

Note: If you are using this code within entries, you will need to use the EE Allow EE Code plugin that allows for EE tags within entries. Even with that solution, you will have to see how EE renders the embed which can potentially break depending on your field formatting options. Alternatively, you can skip this embed and embed the flash code directly, including the category number in the flash var instead of the PHP variable, like so:

That’s it! You can now create category-based galleries on the fly.

Step 6: Modify to Use with EE Fields (Optional)

This method can also be modified to match content within an EE field instead of a category. For example, you can create a gallery of all photos where the event=“My Birthday” or a tag field contains “birthday.” You can of course just use this or the category solution, but I prefer having both available. We can use the same flash file, but need an additional flash embed template and XML template.

Using the same basic settings and code from the category model, create a template for the flash code called “event.” Replace the PHP code at the top with:

Replace the flash var with:

Create an XML template called “xml_event” with the following code:

We’re using the same method of passing the variable, but instead doing a search on the field “photo_event.” So in a few of your weblog entries, in the field photo_event, add a matching event name such as “My Birthday.” Now we can embed an event gallery:

If you’d rather match a keyword or tag within an EE field, instead of an exact event name, you can use this method with a slight modification. Change your variables to reflect a tag and add an EE field for tags. Then, when you do the search in the weblog:entries call in the XML template, change the code to:

You can modify the search as necessary following the EE user guide for the search parameter.

While it takes some set up, you are now ready to create custom galleries based on categories, matching event titles or keywords by inserting a single line of code.

What’s Next?

Next, we will modify this to work with an HTML5/CSS3 gallery, and create a method to import a bunch of photos at once using Solspace’s Importer module.

It’d be great if you’d share any modifications and uses of this method in the comments. Thanks!



1
Erik Reagan
Mar 17, 2010 at 2:34 PM


Nice article and well guided through the process. I do have one question: Why are you using PHP in the XML template when you could just use an EE URL segment for the variable? It will cut down (granted minimally) on the processing time to just use {segment_x} as opposed to declaring a variable in PHP then using it. So instead of having the xmlfile variable “/photos/xml_category?cat=<?php echo $cat_num;?>” you could simply use “/photos/xml_category/{embed:cat}/. Then on the XML file side you can turn off PHP and use {segment_x} rather than pulling in a variable with PHP, assigning an EE variable, then using it in the weblog/channel parameters.


2
Neil Bradley
Mar 17, 2010 at 5:37 PM


Hey Eric, Thanks very much for this. Can’t wait to get trying this and see the results.


3
Eric Miller
Mar 17, 2010 at 6:20 PM


Thanks Neil, hope it works well for you!

Erik, thanks for the feedback. I haven’t fully tested that yet, but I think this should work at least for the category side of this. We went with the PHP so when the variable being passed is field content (such as the “My Birthday”) it would remain intact vs. if it were a URL segment, where spaces and other characters could break the system.

Your idea might work for the field content matching as well, and I’d be curious to see it if you set it up, and I’ll of course let you know if I do the same. Thanks again!


4
Chris
Mar 17, 2010 at 9:58 PM


So, does this essentially eliminate the need of using slide show pro director.  I manage several ee sites that use ssp and it would be great if I could use this to lose director.


5
Erik Reagan
Mar 17, 2010 at 10:23 PM


I’ve actually used SSP and EE a number of times in various ways. The most similar to your approach was on a site that used categories for specific slideshows or combined them all for a SSP gallery look if no category was specified. It used a single XML template that accepted the standard EE category URLs (/slideshow_xml/C4/ or /slideshow_xml/category/trees/ for example).

That’s one thing I continue to love about EE, you can get to a solution with multiple paths :)


6
Eric Miller
Mar 17, 2010 at 11:56 PM


Hi Chris… I don’t have much experience with Director, so I couldn’t say. From what I’ve seen, Director has a pretty nice interface with some good features, so while this solution does give you control over managing individual photos I’m not sure it does everything you want. Would be interested to hear more though…


7
Eric Miller
Mar 18, 2010 at 12:00 AM


Erik, I agree… there are always many solutions within EE, and often there isn’t necessarily a “best” solution.

Sounds like you’re doing something on that site similar to what I do for my personal photo site. There are galleries based on categories… but in that case (unlike this blog post), an entire gallery is housed in a weblog entry rather than just one photo. This is the site: http://myterritory.com


8
John Henry Donovan
Mar 18, 2010 at 3:18 AM


Nice article Eric.

One observation though. I would never use REQUEST but use $IN->GBL() and look for POST or GET only. That way you know where your input is coming from.


9
Chris
Mar 18, 2010 at 8:22 AM


@Eric Miller,

I only use it for uploading photos, giving them titles and then reordering them.  The ssp director interface is very nice, but I might sacrifice some features for integration (e.g. not having to tell people to log in some place else to change photos).  Have you thought of rolling this as an EE plugin or module?


10
Eric Miller
Mar 19, 2010 at 7:28 AM


Chris, I think what would be missing most is control over the order of photos. With this current solution, you’d really be limited to ordering by date. I have thought about making this an add-on, but would want to really refine it first. If something comes together I’ll keep you posted.


11
Chris
Mar 19, 2010 at 9:16 AM


@Eric,

Well you could just create a custom “order” field in your weblog and then sort the results by that when ee outputs the xml file.  That would take care of order!


12
Eric Miller
Mar 19, 2010 at 9:21 AM


Yeah Chris, I used to sort my portfolio that way… but it gets so cumbersome when you want to re-order. Would definitely work though, and not so bad if the order doesn’t change much.


13
Erik Reagan
Mar 19, 2010 at 9:23 AM


@Chris & Eric

Just in case either of you haven’t seen it, there’s the Reeorder Module that can help with that. Elwin Zuiderveld originally wrote it and Lodewijk Schutte took it over for EE 2.0

EE 1.6.x: http://devot-ee.com/add-ons/modules/reeorder/
EE 2.x: http://loweblog.com/software/low-reorder/


14
Eric Miller
Mar 19, 2010 at 10:24 AM


@Erik

Thanks! I haven’t seen that and will definitely check it out.


15
Eric Miller
Mar 19, 2010 at 3:43 PM


@John

Thanks for reading and the suggestion, John… I’ll test that out.


16
Victor Acquah
Mar 24, 2010 at 10:09 AM


If the images were hosted on amazon s3, what will the workflow look like? (I have purchased the bucketlist extension, but not sure how to implement something like this and pull the images from amazon).


17
Eric Miller
Mar 24, 2010 at 1:33 PM


@Victor

I haven’t done this yet, but I’m actually considering it for a project I’m finishing up this month. I’ll post the results here if it works out.


Add a Comment:



Notify me of follow-up comments?