How to : Integrate a slideshow in your wordpress theme
Posted by X-OR on Jul 31, 2008 in Blogging, featured, wordpress • 86 commentsIn the previous tutorial i explained how to make a control panel for your theme, now let’s go further with the integration of Smooth Gallery (from JonDesign), a javascript gallery based on mootools.
In this tutorial, i will also use mimbo (from Darren Hoyt).
Most theme don't use all the possibilies of wordpress and smoothgallery. In some of them (like massive news) you must hardcode the links to the post in the control panel. That's why i decided to do this tutorial.

this is what it will look like
you can see working example on the main page of this site
What do we need ?
The first thing we need to do is to download SmoothGallery 2.0
First Step : Put the files where they have to go
Unzip your smoothgallery archive
copy the css directory to wp-content/themes/your_theme_name
copy the scripts directory to wp-content/themes/your_theme_name
Once this first step is done, we have all ressources needed to run the SmoothGallery on our blog
Second Step : Add the reference to the files in your Header
Add these lines in your header file (wp-content/themes/your_theme_name/header.php)
<!--Css SmoothGallery-->
<link rel="stylesheet" href="<?php bloginfo('template_url'); ?>/css/jd.gallery.css" type="text/css" media="screen"/>
<!--JS Mootools-->
<script type="text/javascript" src="<?php bloginfo('template_url'); ?>/scripts/mootools.v1.11.js"></script>
<!--JS SmoothGallery-->
<script type="text/javascript" src="<?php bloginfo('template_url'); ?>/scripts/jd.gallery.js"></script>
Once this step is done, SmoothGallery is ready for use in your theme
Third Step : Create the file gallery.php (in your theme directory), this file will generate the html code to show your gallery.
before starting this step, bear in mind the structure of a smoothgallery element
<div class="imageElement">
<h3>Item Title</h3>
<p>Item Description</p>
<a href="Link to Item " title="open image" class="open"></a>
<img src="Image of item" class="full" alt="Item Title" />
<img src="Thumbmail of item" class="thumbnail" alt="thumbnail of Item Title" />
</div>
In the gallery.php file there are two parts.
The initialisation of the SmoothGallery Script (JS)
The creation of the html/php code for the gallery

you can download the proper code here
<!-- Initialization of SmoothGallery-->
<script type="text/javascript">
function startGallery() {
var myGallery = new gallery($('myGallery'),
{timed: true});}
window.addEvent('domready',startGallery);
</script>
<!-- Creation of the html for the gallery -->
<div class="content">
<div id="myGallery">
<!--
Get the 5 lasts posts of category which ID is 3
(to show the recent post use query_posts('showposts=5');)
-->
<?php query_posts('showposts=5&cat=3');?>
<?php while (have_posts()) : the_post(); ?>
<!--get the custom fields gallery_image
(fields which contains the link to the image to show in the gallery)
-->
<?php $values = get_post_custom_values("gallery_image");?>
<!-- Verify if you set the custom field gallery_image for the post -->
<?php if(isset($values[0]))
{?>
<!--define a gallery element-->
<div class="imageElement">
<!--post’s title to show for this element-->
<h3><?php the_title(); ?></h3>
<!--post’s excerpt to show for this element-->
<?php the_excerpt(); ?>
<!--Link to the full post-->
<a href="<?php the_permalink() ?>" title="Read more" class="open"></a>
<!-- Define the image for the gallery -->
<img src="<?php echo $values[0]; ?>" class="full" alt="<?php the_title(); ?>"/>
<!-- Define the thumbnail for the gallery -->
<img src="<?php echo $values[0]; ?>" class="thumbnail" alt="<?php the_title(); ?>"/>
</div>
<?php }?>
<?php endwhile; ?>
</div>
</div>
Fourth step : include the gallery in your theme
With mimbo it's really simple, you only have to replace all the code between these two lines
<div class="feature clearfloat" id="lead">
</div><!--END FEATURE-->
by
<?php include ('gallery.php'); ?>
once this is done, your gallery is working (if you have set the custom field of your posts of course)
If you are using another theme, it's not a problem, you can put the include wherever you want
Last step (not mandatory) : Customize your gallery
open the file wp-content/themes/your_theme_name/css/jd.gallery.css, you can set the height and width of your gallery.
#myGallery, #myGallerySet, #flickrGallery
{
width: 590px;
height: 250px;
z-index:5;
border: 1px solid #000;
}
you can also modify the options of your gallery in wp-content/themes/your_theme_name/scripts/jd.gallery.js
more info on customization on Smooth Gallery Website















NO friggen working example?
Josh,
The blog homepage features a SmoothGallery.
I have been visiting your blog since I first discovered you and I continue to be impressed by the effort that you put into your blog. Its nice to visit useful sites.
Hello! forgives, I continue all the steps, but I get a black box loading forever. Does where I failed? Can you copy the code “gallery.php” of your site? (because that is included in the post has two errors) thanks!
Hi Dani,
i have tested again the gallery.php and it works for me, did you see the link to the “copy/paste” version of the code here try with it.
If it doesn’t work, leave me a link to your code so i can have a look and help you to make it work
@Local SEO Phoenix: Thank you for you interrest and your kind words!!!
Thank you for your reply! He left the plugin enabled to have a look in my page. the code gallery.php is this:
function startGallery() {
var myGallery = new gallery($(’myGallery’),
{timed: true});}
window.addEvent(’domready’,startGallery);
<a href=”" title=”Read more” class=”open”>
Do not let me copy the code:) But I think the problem I have is that not that field I have to customize to create the post so that it recognizes as part of the gallery
“Verify if you set the custom field gallery_image for the post –”
This is a really good tutorial, I am going to include it on my reworked homepage to be released soon…. Thanks!
@Dani: did you create the custom field ???, i you have still problem contact me by mail : joydivision78(at)gmail(dot)com
@Tim Norton: Thank you, say it to me when it’s released so i can have a look !!
@X-OR: You bet! I’m doing a lot of work on it this week so hopefully in a day or two.
Nice tutorial. I will bookmark it for future reference. Thanks.
I wanted to use SmoothGallery to showcase my work on my home page but finally I went for MooFlow which is not bad as well.
OK, you can see the finished gallery on my website. One thing, you have to create a custom field called ‘gallery_image’ and put make the value (for each post) the image you want to display in the slideshow about that post, for instance ‘nice-pic.jpg’. Then make sure the gallery.php path to the images is correct (site.com/gallery/) etc. Those are a couple things that got things working for me. Thanks for the tutorial!
@Jeeremie: Thanks, i’ve taken a look at your mooflow showcase and it’s nice, kinda different than smoothgallery. i will try it for another project: Thanks
@Tim Norton: Nice one !!!!, thanks for sharing you experience here !!!!
Great tutorial, wae are building so many WP’s for clients now, thanks for the info
Steve
hi,
i have a problem :S
i only see ajax loading bar and black screen and excerpt
how can i solve this probem ?
hi sryr,
look at the path to your image the problem come probably from there, if you want you can let me the link to your work so i can have a look.
Hi X-OR,
thanks for reply
how can i declare a path for images,
i want to use smooth gallery on right sidebar with my wordpress website. i was working on local server, and i try to integrate my new wp theme design. if i can not solve this problem i can load a demo to web server and you can check , if i can solve this problem i will be happy so much. Coz i tried last night and not find any solution
Hi sryr,
did you specify the custom field for each post you display ?
You can contact me by mail joydivision78(at)gmail(dot)com.
i sent an e-mail for you. pls check it.
i solved problem now
thanks you X-OR,
it works now very well,
Great news srvyr,
you’re welcome
thanks a lot
Hi guys,
In case any of you run into the problem where your slideshow does not load and all you get is the loading page, it is related to the fact that the Mootools library being used by SmoothGallery is not compatible with other AJAX libraries. Specifically prototype.js. I spent nearly an entire day trying to find out why it was not working on my website. Anyways, I came up with a PHP patch in my template that simply checks to see if your current page should load prototype.js or the Mootools library. So far, so good. If anybody needs help, you can use the following form to contact me: http://www.ipodstuffreviews.com/contact/
Good job, everything work. But… I would like to change font size in gray infopanel (post title and excerpt). I try change this in jd,gallery.css and layout css… but it doesnt work
Hi Guys,
I don’t get it to work. Sorry for any dummy questions but should I customize something in gallery.php? I have given some posts in wordpress the custom field “gallery_image” as value (what should i give in for key?). Also I get an error “Handler could not be removed”. Could you help me out please?
Thanks!
Tom
Hello guys,
I am following up on my previous mail concerning the fact that I can’t get in run.
In wordpress I’ve added a custom field:
key: gallery_image value: path of the image itself /blog/wp-content/../image.jpg
Is that OK? For the rest I’ve put gallery.php under themes and copied the content “as is”. Any customization needed here?
I still get the message: “Handler could not be removed”.
Thanks for you support!
Regards,
Tom
@Tom: X-OR, who wrote this article, is away today, but will answer you tomorrow. Stay tuned
Thanks jbj !
@honza.: you have to locate in the file css/jd.gallery.css : you can change these 2 class.
.jdGallery .slideInfoZone h2
{
padding: 0;
font-size: 14px;
margin: 0;
margin: 2px 5px;
font-weight: bold;
color: fff;
}
.jdGallery .slideInfoZone p
{
padding-left: 5px;
font-size: 10px;
margin: 2px 5px;
color: #fff;
}
if you still have problem contact me by mail joydivision78(at)gmail(dot)com
@Tom:
try to put in key :gallery_image and in value : the full path to the image
do you have an example online so i can check what goes wrong
you can contact me by mail (same adress as previous comment)
I’m kind of lost on installing this, here’s where I get lost?
1. “Then make sure the gallery.php path to the images is correct (site.com/gallery/) etc.” What line of the gallery php is this, I can’t find where I insert my path?
2. I get lost at Step 4. I can’t figure out what to do here:
Fourth step : include the gallery in your theme
With mimbo it’s really simple, you only have to replace all the code between these two lines
by
Any help would be appreciated. Thanks!
PS I added the custom field to my latest post, but the key only has the file name, not the full path.
@Larry Bradshaw: Hi,
the 1st point you’ll have to modify the code in gallery.php if you only set the file name in the key value
the 2 lines starting with < img src=”
you’ll have to put the full path to the directory where you put your image files. like
<img src="http://www.mysite.com/feature/<?php echo $values[0];?>
for the second thing you’ll have to put where you want your gallery to appear the code
<?php include (’gallery.php’);?>
if it doesn’t work mail me at joydivision78(at)gmail(dot)com
@ X-OR: Thanks for your feedback!
I’ve already implemented it as follow in wordpress:
key: gallery_image value: http://www.luxurytravelbutler.com/blog/wp-content/themes/default/images/brazil-travel-package-great-brazil-express.jpg (so the full path)
Still got the error message: “Handler could not be removed”
Is there any customization needed in gallery.php? Is the place where I put the scripts & css important? Have a look at my http head @ http://www.luxurytravelbutler.com ; I assume there is no problem there ; so it has to be something else…
Can I add you to MSN so I know when you’re online ; then I can set up everything to have a look at. (problem is that I have to test on when the site is live).
Thanks for your support!
Tom
Hello,
I have, despite my lack of coding-expertise, tried to implement the slideshow into my WP-theme (Thesis 1.1), but have only gotten half-way. What I cannot figure out (and what surely makes me into a laughingstock) is where exactly to put the ’structure of the smooth gallery element’.
i.e.
-
etc
Without it my posts are in fact connected to a specified image through a custom field, but they do not display any text or, indeed, slide. I have found this tutorial to be highly useful so far, and if you can help this lost n00b I would be most grateful. Thanks a lot
div class=imageElement
etc,
is what I am referring to
@Kneff : i’ve looked at your development site, (i saw it on the diy forum) and you’re element are empty. did you put the correct category id here
it will probably work, cause in your site all elements are empty it means query is not good.
Mic
Ah, a fellow Thesis-user! I have tried my best to figure out where to input the right information, but to no avail. Therefore my question is very n00bish, but I don’t know what/where my element is?
Could you possibly point out what file it is, .php och custom.css or a custom field? I am looking forward to having my slideshow not only displaying a black box
Thanks for the support
@Kneff: All your element are generated in the gallery.php page.
so your query is not good (otherwiste you will have at least the post title displayed)
look at this line query_posts(’showposts=5&cat=3′); and replace it by query_posts(’showposts=5&cat=3′);
and tell me if it changes something.
Pardon my ignorance, but is not the replacement line the same as the default? I feel a bit like a blind man trying to climb a tree, but I appreciate the guidance
@Kneff: sorry i mean replace by this query_posts(’showposts=5′);
It works, time for tweaking!
Thanks a bunch, this certainly did light up my Friday. Can I also ask how to display my slideshow on every page and every post, if that is possible? Again, thank you very much
To my great joy, I figured that one out myself, happiness!
However, I am struggling with changing the font size of the displayed text, i.e. the excerpts from the posts. I have been changing various options in jd.gallery.js but without finding the correct lines of code that controls this. Any suggestions?
@kneff : it’s great, i’m glad it finally works for you. to change the style of your excerpt look in the file css/jd.gallery.css and change the style in .jdGallery .slideInfoZone p.
Thx a lot for the support, it has helped a lot
Really want to first say great tutorials! This was easy to follow and slideshow works great. Is there a way to call the posts in a specific order, perhaps by ID?
In other words if this is the query is there a way to make the slideshow pull posts in the specified cat order?
Thanks again!!
Hello again,
Now that I have got my gallery working properly (many thanks) I want it to only display certain posts (which thus need to be defined by an exclusive category, I reckon?) - but as it is now the slideshow displays all posts regardless of category. I have tried to specify in gallery.php that I want a specific category, like so:
[ ?php query_posts('showposts=5&cat=X');?> ]
However, it either ignores this command and continues to show each and every post, or it displays nothing. Again, it feels like there is a very obvious solution to this problem, and hopefully this is not a problem for the knowledge of this forum. A bunch of kudos for this great tutorial!
@JB: you can specify in your query_post, order and orderby
like this : <?php query_posts(’showposts=5&cat=3&orderby=title&order=ASC’);?>
order : ASC or DESC
orderby : post_date, title, category, author, name
i hope it will help you
Hi X-OR,
I followed the tutorial and searched through the comments but still can’t seem to solve my problem.
Basically what I got from the gallery is just the title,excerpt, and thumbnail. The main image is not displaying. Here’s a screenshot.
You can visit mysite to look at the structure. I implemented this in the sidebar for your info.
Additionally, when I tried to implement this in my main loop, I get the same results, plus the rest of my post are not showing up. Think you be kind enough to take a look?
Hope I’m not asking for too much. : )
Thanks.
@Neowster: Hi, i had the same problem (image not showing) for another site, and i finally find what’s the problem. this happens when there is only one element. i think it’s a bug of smoothgallery. try with a second element in your gallery.
for your second problem i need to have a look at your gallery.php
Mic
@Kneff: it’s very strange, can you mail me you gallery.php so i can try to locate the problem
X-OR,
Thanks. You were spot on! Its working now.
As for the second problem, my gallery.php is what you supplied, just minor edit to the showpost and cat where necessary.
Once again thanks for your help, not just to me, but to all the timely reply for all questions posted in this article.
Regards
Noel
@Neowster:Thanks, i’m glad helping people to have nice website
i copied your gallery.php in my template in place of mine (modifying only the custom_key name) and it works perfectly. maybe you did not set all the custom key fields for each article.
look at the custom fields and keep me informed.
Mic
X-OR,
Thank you for the follow up. I knew I needed to use order_by somehow and since I was pulling posts from multiple categories the key was to drop showposts as that I guess is redundant?
So the following seems to work: php query_posts(’cat=x,x,x,x&orderby=category’);
Many thanks again!!!
thats pretty useful and nice wordpress tutorial there are only a few tutorials for wordpress (other than css) available from which this is one of the best,
Nice tutorial, very useful , I got a problem, maybe someone else got the php code that iPod Dude said, I wanna make this work with another js. Now it doesn’t work if I use prototype.js and I need to use this also. Beside this, it works fine. Thank you for your tutorial.
I have tried all day long to get this script to work on a client’s website to no avail. All that happens is the gallery.php include loads the 5 most recent post in the div. Can you take a look at what I have done and what I am doing wrong here.
From what I can tell the script is not loading at all. Maybe there is a conflict with another script that the site is running? Thanks.
I thought I could embed a link in your comments. The URL is http://www.vidagirl.com. Thanks again. Any help would be greatly appreciated.
@Erik & Ionut: you can download here a namsespaced version of smoothgallery to avoid incompatibility with other script.
try with it and tell me if it works
Mic
Thanks. The script loads, so there must have been a compatibility issue, but that is all that happens. The excerpt text changes, so I know that the loop is fine. But, there is not title for each post and no image. Sorry to be a pain about this, but your help is definitely appreciated.
Thanks again.
Same here.
I’m getting a few problems (assume they are compatibility related)
Initially, it worked. Then I changed a few images, and the div just filled with the images and text (no smooth gallery effects).
I tried to download the namespaced version, uploaded the new scripts, and changed the references in the header file to point to the namespaced versions:
But now, I just get a blank box where the gallery should be (firebug shows me the gallery is there, but display is set to none).
site is: http://daisygreen.21creatives.com
Any thoughts?
Thanks in advance,
Roger
Problem update:
I created a vanilla wordpress (2.6.1) installation
Placed the smoothgallery in the index.php file
If I use no imageElements, I see the javascript gallery, picture tab, and black scrolling bar
As soon as I add imageElements, the javascript effects go and my div simple fills with the text and pictures from the Elements.
Site is: http://testarea.21creatives.com
I’d love to be able to use the gallery, any thoughts would be appreciated.
Thanks again, Roger
I have tried it and I have gotten nothing to work. There isn’t even a gallery on my site. It is just empty:
http://www.juuble.com
I have sent an email of the code. I don’t know exactly what I am doing wrong. I don’t know which file to change things in step 4, but I changed it in index.php, since I didn’t know which file to replace it. I am using Mimbo.
Hi,
Implemented this successfully, but can anyone enlighten me on how to hide my content during the initial “loading”. Basically during the initial load, you see the “flash” of all the content “overflowing”. I see that the script loaded at this site is facing the same issue. Thanks.
i installed it and it works great, this is what i was looking for
Hi,
The title and exerpts for my posts that show up on the slideshow are in tiny fonts (paragamer.com), how can i change this?
Regards,
Tom
Hi all,
first of all, sorry for my english, i dont speak it very well….
Thank you very much for this tutorial, it’s amazing… but… i have one problem… the code of the gallery.php that you put on the tutorial, has a query_post() function that encounters a problem with my other posts…
If i put the gallery.php in my theme through the <?php include…., the loop within gallery.php overwrite the loop on my theme, and it doesn’t works properly.
In Wordpress codex, i have found this:
http://codex.wordpress.org/Template_Tags/query_posts#Important_note
it’s exactly my problem… the codex says that its better to use the wp_query function… but i dont know if i can use that like query_posts, only on certain categories…
Please, anyone can help me?? its very important… thanks
@NaSHoOo: Here’s the syntax for the wp_query object:
<?php $recent = new WP_Query("offset=1&showposts=5");
while($recent->have_posts()) : $recent->the_post(); ?>
//WP loop
<?php endwhile; ?>
@jbj: thank you very much for reply, but i’m starting with wordpress themes developing and php… can you modify for me your gallery.php (the gallery.txt code on the tutorial) with this fix and send it to me?
Sorry for the inconveniences… and again, thanks for the help!
Hi,
I’m helping a friend edit his wordpress theme, look here I’m trying to figure out how to put the slideshow above the first 2 collumns from the left whilst leaving the right sidebar intact.
When I try to do this the three collumns usually move so they are on top of each other on the left?
Anyone know what I can do?
Thanks
Ohh by the way this does not work if you have the Lightbox wordpress pulgin installed
is there anyway to eliminate the black box that shows the text? I don’t mind the text showing up but I would love to get rid of the black box entirely. or make it not so high or not so dark?
Hi,
Slide show is not working in single post and page it’s working fine in home page i.e index page .My slide show is in sidebar .For more inforamation you can go through my site http://www.indianomics.com Please help me out .
Thankyou