How To Make a jQuery Image Slideshow in Thesis

by Matt on February 15, 2010

Updated! 03/23/10

Well I can’t spell apparently. I had misspelled ‘slideshow’ in the code below. The issue is fixed and my wife is now administering me weekly spelling tests. Thanks, Scott and Willie.

Slideshow Made Simple

Making a jQuery image slideshow in Thesis is actually very easy. There are four basic steps:

  • Insert a few lines of code into the header.
  • Make a slideshow <div id="slideshow">.
  • Put some images into your images folder.
  • Write a little custom.css code magic.

To begin, I want to outline a few assumptions. I am going to assume that you have images of the same size (height and width). Also, although you can put any HTML into a “slide” I will only be using images. Lastly, I will be using a default transition effect called “fade” and I will not be adjusting all of the variables. In fact, if you read the Cycle Plugin documentation, you will see that there are about a million tweaks possible.

Update 2/18/09

For the sake of this tutorial, I am going to assume that you only want the slideshow to appear on your home page. If you want the slideshow on every page simply remove if (is_front_page()){...........}. Also, never be embarrassed to ask me for help! I am the Thesis Tutor, after all. ;)

Now, onto the juicy parts!

First, copy and paste the following into your custom_functions.php:

function slideshow() {
if (is_front_page()) {
?><div class="slideshow">
    <a id="slide1" class="slide" href="http://yourblog.com/link"></a>
    <a id="slide2" class="slide" href="http://yourblog.com/link2"></a>
  </div>
<?php
}}
add_action('thesis_hook_after_header','slideshow');

function slide_script() {
echo "\n\n";
?>
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.3.2/jquery.min.js"></script>
<script type="text/javascript" src="http://cloud.github.com/downloads/malsup/cycle/jquery.cycle.all.2.72.js"></script>
<script type="text/javascript">
$(document).ready(function() {
    $('.slideshow').cycle({
	fx: 'fade' //You can change transition effects here.
	});
});
</script>
<?php
}
add_action('wp_head','slide_script');

It is important to note that you can add as many images as you please, just be sure to give them each a unique id so you can target them later in the CSS.

Next, drop the images you want to use in the slideshow in your images folder.

Last, we need to add some CSS to whip this little slideshow into shape. So, open up your custom.css and paste this little bit of code in there:

.custom .slideshow .slide { display: block; height: ---em; width: ---em; outline: none; }
.custom .slideshow #slide1 { background: url('images/image-1.jpg') no-repeat; }
.custom .slideshow #slide2 { background: url('images/image-2.jpg') no-repeat; }

Be sure to insert your images names and height/width. By default, the font-size is 10px. Therefore, to convert to ems, simply divide pixels by 10. Yes, it is THAT easy.

That should cover it, folks. Happy coding!

{ 2 trackbacks }

{ 66 comments… read them below or add one }

Scott February 17, 2010 at 5:11 pm

not working for me.. do I need to put something in between and ?

Reply

Scott Wyden Kivowitz February 17, 2010 at 8:32 pm

I just realized why it wasn’t working for me. You have a typo function slidewhow(

Once I changed it to slideshow it worked!

Reply

Scott Wyden Kivowitz February 17, 2010 at 8:42 pm

Scratch that.. now that is is working it shows up on every page

Reply

Scott Wyden Kivowitz February 17, 2010 at 8:45 pm

Sorry about the multiple comments but I figure updates can’t hurt :-)

Added if (is_page(‘home’)) {
}

to make it only show on the home page

Reply

Matt February 18, 2010 at 12:48 am

@Scott
You can use is_home as you did. However, a much better way is to use is_front_page. That way, whether your home page is posts or static, the slideshow will show. I’ll be sure to add this to the tutorial. Thank you for not biting my head off for not having a video! I need to get it in gear over here :D

Reply

Scott Wyden Kivowitz February 18, 2010 at 7:27 am

That worked too. I wasn’t sure if it would because I have a custom template for the home page but you were right.

You rock for coming up with it Matt!

Reply

Matt February 18, 2010 at 9:00 am

@Scott
Thanks!

Reply

Nick February 19, 2010 at 7:32 pm

Dude, awesome tutorial. Glad to see someone finally made an easy to follow one :)

Reply

Ryan McMahon February 20, 2010 at 1:54 am

hi matt

i’d like this to show on all pages. which line do i remove exactly. i see what you’ve posted above, but it doesn’t look to be in the code i copied from the tutorial.

HERE IS THE LINE YOU SAY TO REMOVE ABOVE:

if (is_front_page()){………..}

Reply

Matt February 20, 2010 at 7:54 pm

@Ryan
Just take out if (is_front_page()) { and one of the } before add_action('thesis_hook_after_header',.

Reply

Ayo February 26, 2010 at 10:47 am

Added the code, when i load my page, it displays ALL my images, then reverts it to a single display after about 2 seconds. why is this ?

Reply

Matt February 26, 2010 at 1:09 pm

@ayo
Probably one of two things: large image sizes or a slow server.

Reply

Silver March 1, 2010 at 9:03 am

Hi, this is very nice tutorial, easy to follow.

But still I have few questions, because my slideshow don’t show the images.

In this field below:

href=”http://yourblog.com/link”
href=”http://yourblog.com/link2″

This the destination where it goes when someone clicks the image, do I understand correctly?

And the CSS:
images/image-1.jpg – this format doesn’t seem to work for me, as the site isn’t showing the images, only blank white space.

A little help is needed here :)

Reply

Matt March 1, 2010 at 9:30 am

@Silver
The href=”….” is the link. In the CSS, you simply put the image location. So, if you put your images in the custom images folder and the name of your image is ‘matt-at-work.png’ you would put ‘images/matt-at-work.png’ in the CSS. If you upload your image via wordpress interface your image location will look something like this: http://yourblogname.com/wp-content/uploads/2010/02/imagename.type

Reply

Silver March 1, 2010 at 10:11 am

Thank you very much it worked for me. :)

But how can I put some text on that slideshow field? And also add a cool frame to it?

Maybe you can direct me to somewhere, or give the answers yourself.

I would really appreciate that. :)

Reply

Matt March 1, 2010 at 11:03 am

@Silver
I will be doing another tutorial that shows how to further customize the slideshow. Until then, I can only recommend looking at the Cycle Plugin tutorials.

Reply

Silver March 1, 2010 at 5:48 pm

Okei, looking forward for that tutorial.

And will be implementing the Cycle plugin tutorials.

Reply

Brendon Mulvihill March 6, 2010 at 5:33 pm

Great site Matt…just found it. I feel stupid for asking this question…but do you need the Cycle Plugin in order for this to work. I did everything above…and it doesn’t work. But I have a feeling it’s because I’m missing the plugin. Thanks.

Reply

Matt March 8, 2010 at 2:08 am

@Brendon
The plugin is called via a <script> link in the head. It isn’t a plugin in the Wordpress sense of the word. If you would like to email me your site I will look at the source real quick and see if there is a mistake.

Reply

Marie March 9, 2010 at 10:43 am

I uploaded both the css and the function code, but absolutely nothing is showing up at all on my home page. I uploaded the images into my custome images file and changed the image names to reflect that in the code as well as the height and width. What am I doing wrong? new.simplyadele.com

Reply

Matt March 9, 2010 at 1:25 pm

@Marie
I don’t see the slideshow in your markup at all. First, delete and copy/paste back in the custom_funcitons.php part. If still nothing, try changing thesis_hook_after_header to thesis_hook_before_content_box. If nothing still, you will have to email me the contents of your custom_functions.php as I cannot see server side code.

Reply

Marie March 9, 2010 at 2:34 pm

I changed it to thesis_hook_before_content_box and still nothing. Do you think it might have something to do with how I’ve put the menu bar below the header? I can’t seem to find your email address to send you the php file.

Reply

Matt March 9, 2010 at 2:54 pm
Marco Ryan March 11, 2010 at 10:36 pm

Great tutorial. I had it working fine on Safari and briefly on Firefox, but then today – having made literally no changes honest! – it only works on Safari!
I have rebooted, re-uploaded a clean version of the code (not that I made any changes)
http://www.focusforhumanity.org/wordpress
Any suggestions?

Reply

Matt March 21, 2010 at 2:23 pm

@Marco
Looks good to me!

Reply

Scott March 23, 2010 at 6:23 am

Marco,

The website looks awesome!

It’s working for me in all browsers as well.

Reply

Dee March 24, 2010 at 6:17 pm

Not smarter than a 5th grader here. Does this script allow speed control? What are the correct terms/words/parameters, et al to use for changing the transition effect? Can this work in the Thesis Feature Box? Last question. This looks like just what I need. I also need to put music to it. Any suggestions for accomplishing that?

Thanks in advance.

Reply

Matt March 25, 2010 at 5:09 pm

@Dee
In order to take advantage of the controls, I will have to refer you to the plugin documentation. There are sooooooo many things you can do. For beginners, put a comma after fx: 'fade', then add speed: 700. You’ll be able to play with it from there. Just follow the documentation.

Yes, it can work in the feature box. As far as music, there are a million plugins. I don’t use any, but you shouldn’t have trouble finding one. I’ll ask around though.

Reply

Dee March 25, 2010 at 11:13 pm

Thank you Matt! I will try the code tomorrow. I’m crossing my fingers that it’s the answer I’ve been looking for and that I can implement it properly. And thanks for answering about the attribution. I will look into that also based on your suggestions.

Reply

Dee March 30, 2010 at 8:02 pm

I get this error after inserting the code:

Parse error: syntax error, unexpected ‘<' in /mnt/w0805/d01/s15/b0307eb7/www/bytethenet.com/wp-content/themes/thesis_16/custom/custom_functions.php on line 79

I don't know what to correct.

And is this the right way to do the css for the images?
.custom .slideshow #fp083 { background: url('http://bytethenet.com/wp-content/uploads/2010/03/face-paint-083.jpg') no-repeat; }

(I'm confused. Why wouldn't it be custom.slide?)

Reply

cayce March 30, 2010 at 8:32 pm

Thank you for this great tutorial.

Right now I have the slideshow before content box: using ‘thesis_hook_before_content’

It is left aligned and looks funky. How would I center the slideshow?

Reply

Matt March 31, 2010 at 11:14 am

@cayce
If you send me a link, I will take a look at it :)

Reply

Dee April 1, 2010 at 12:42 am

Hi…can you give me any idea about the problem I posted above on 3/30? I really believe this script is what I’ve been looking for, and I’m anxious to get it working.

Thanks in advance

Reply

Dee April 1, 2010 at 8:25 pm

I found a good substitute.

Reply

Matt April 2, 2010 at 8:48 am

@Dee
Many times it takes me more than 48 hours to get around to answering questions on this blog for free. Your answer is this: somewhere in the code you have inserted an extra ‘<'. I just copied and pasted the code I have in the tutorial, wondering if it was messed up, and it worked perfectly. No errors at all. So, unless you would like to send me the contents of your custom_functions.php I can't say where you added the '<' in.

Reply

MJ April 3, 2010 at 9:21 am

I am getting a weird error myself:

Warning: call_user_func_array() [function.call-user-func-array]: First argument is expected to be a valid callback, ‘slideshow’ was given in … on line 339

I am on WordPress 2.9.2 and using Thesis 1.7. Any ideas?

Reply

MJ April 3, 2010 at 9:29 am

the “error was due to a a BAD Ctrl+V on the function NAME.”

Reply

Silver April 5, 2010 at 4:07 am

The slideshow isn’t working for me anymore.

As I read above, the problems that the slideshow isn’t showing the pictures correctly are, large image sizes or slow server.

I looked at my files, 55kb and so on, so they’re not large. This leads to a slow server then? How can I fix that? Only to host in some other place?

Any help would be appreciated Matt.

Reply

Jean April 10, 2010 at 8:44 am

the same case for me, there is an empty area for the slideshow but not images shown
whene I click on it I can see one image on an other window, what is wrong?

Reply

Matt April 10, 2010 at 1:23 pm

@Jean
You’ll have to send me a link to the site you’re working on.

Reply

Dee April 17, 2010 at 10:08 pm

I had a weird one. I re-copied and re-loaded the function. That went well. On my front page, there was movement — my header, footer, and title were rotating. Go figure. I’ve rechecked my image urls – nada. It turns out that I needed to include the page in Thesis navigation, not just select it as my front page. Everything works! I’m so glad I kept trying. I really like this script. Can you share what you told the other poster about centering the slideshow?

Thank you for the script!

Reply

Matt April 19, 2010 at 9:59 pm

Centering is different from site to site. Glad you figured this tutorial out for your install! Feel free to send me a link to your site.

Reply

Doug May 9, 2010 at 4:19 pm

Hey Matt,

What a wonderful tutorial. Very clean, very articulate. One quick question: I’m using a test site right now before I deploy to a published site and for some reason both my test images are appearing stacked on top of each other and no transition. Any ideas? Test site is http://www.bearfootcreative.com. Thanks in advance!

Doug

Reply

Doug May 12, 2010 at 3:21 pm

Hey Matt,

Still hoping to hear from you on a suggestion for why my images are stacking (www.bearfootcreative.com). I’ve double- and triple-checked and I’ve copied the PHP and CSS just as you have it. I tried changing the hook position, no luck. Any other ideas? Do you need to see the PHP?

Doug

Reply

Matt May 13, 2010 at 3:42 pm

Remove this <script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.3.2/jquery.min.js"></script> from custom_functions.php.

See if that doesn’t help ;)

Reply

Doug May 14, 2010 at 8:14 am

Rats! The images are still stacking. This is exactly what I have in customfunctions.php. Thanks!

function slideshow() {
if (is_front_page()) {
?>


$(document).ready(function() {
$(‘.slideshow’).cycle({
fx: ‘fade’ //You can change transition effects here.
});
});

<?php
}
add_action('wp_head','slide_script');

Reply

harris dude May 24, 2010 at 12:04 am

hi, how can i make this work on a static page? i appreciate it. thanks

Reply

Lisa Vickery July 11, 2010 at 6:49 pm

Hi Matt,
Love your site. I drop by frequently. I have tried the slideshow, but can’t seem to make it work. Any suggestions?
Thanks,
Lisa

Reply

ian harrison July 19, 2010 at 1:27 am

i had your slide show working but as soon as i put another featured content slider on the page the j query messed up.

Is it possible that it was the word ‘slideshow’ in the code? if so can it be changed to say slideshow2?

Is it even possible to run it with a featured content slider working at the top of the page?
if so i will re load it when i get a suitable FCslider, what do i need to watch out for when i load it next time?

thanks,

Ian

Reply

ian harrison July 19, 2010 at 6:49 pm

me again, i have re loaded the script and have replaced the featured content for your script.
so no i was wondering is it possible to have two of these slideshows on the same page?
If so what to do?
Cheers

Reply

Charles Smith July 24, 2010 at 2:13 am

I got the slideshow working perfectly – thank you for tutorial. I have the same picture, but with different text over 8 seperate images and when it “fades”, it makes the picture flicker. I understand its the fade effect that makes this happen. I would to have the pictures switch without fading, so it would appear that the next text is popping up (sort of a lazy mans flash).

Do you know what I could replace the fade with to simply have the next picture switch without a fade?
I hope I made sense. Thank you.

Reply

Matt July 25, 2010 at 1:22 am

To change the effects, visit the Cycle website and read through the different effects and how to achieve them.

Reply

Mireille July 25, 2010 at 2:30 am

Hi Matt, I have used your tutorial found it easy and all works except for two annoying things, I cannot find a way to solve.
If I have 3 or 4 images while the page is loading all the images are visible at the same time on the screen. That is awful from a visitor point of view I would hit the back button. Yours does not do that so I am wondering what I am doing wrong.

The second thing is the alignment if you can suggest how I can align it better great if not I can learn to live with it until I figure out a way. One of my problems with thesis and I am not sure it is thesis specific but it does not render the same in all browsers. I do something on the mac then I faint when I open a window based machine.
the site if you would look at my problem is http://www.internethomealliance.org I am not a coder so please keep it simple.

Thank you
Great tutorials

Reply

Charles Smith July 27, 2010 at 2:54 pm

Thanks Matt – the “wipe” effect did the trick, but now I have another issue. I am not a programmer and cannot figure out how to code the script to preload the first couple of slides before the slideshow begins. As of now, all 8 images will sometimes stack on top of one another for a brief moment while the page loads and it looks bad. I’ve tried to code it myself, but can’t get it to work.

Any help is greatly appreciated.

Thank you.

Reply

Steven Priddy July 31, 2010 at 10:40 pm

Check your css for the div containing the images for position:relative; It should be position:absolute; to keep the images from stacking. I haven’t used this script but that seems to be the problem. I am trying to put a contact form script on a site for someone and had the same issue of stacking. The above method is how I fixed the stacking problem. Now if i can just figure out why their slideshow doesn’t work if my form is on their page I will be good to go.

Reply

Charles Smith August 4, 2010 at 12:23 pm

Steven:

THANK YOU! That seemed to fix the stacking issue…

Reply

Dev August 15, 2010 at 4:20 am

I tried using this solution (with position:absolute) but it just stacks the images on top of each other. I can’t see any transitions happening. There is no animation at all. I can just see the last image.

Any help please? Have been trying to get a slideshow up on my site (local as of now) for the past 2 days but can’t seem to get it to work.

Mireille July 28, 2010 at 2:32 am

Hi Matt, I see some comments posted after mine were approved but mine is still waiting moderation. I hope that this comment will bring it to your attention. I have reduced the number of pictures I used just because the loading is so annoying with all the images displayed. I sure could use your advice. The link to the site is in the previous comment I sent.
Thank you, I hope.

Reply

Matt July 28, 2010 at 8:48 am

It is related to image size and server speed. I have optimized my images to be formatted for the web and I serve them from a CDN.

Reply

Charles Smith July 30, 2010 at 12:25 pm

Hi Matt:

I’ve included the script I’m using with the “wipe” effect for the slideshow. I don’t know jquery programming and can’t seem to figure out how to get the first few slides to preload befroe the slideshow starts. As of now, when the page loads, all the images stack on top of each other. By the looks of it, someof the other commenters could benefit from the same solution. If you get a moment, can you please show me the code and where to put it to accomplish preload? Thank you.

function slide_script() {
echo “\n\n”;
?>

$(document).ready(function() {
$(‘.slideshow’).cycle({
fx: ‘wipe’,
speed: 500,
timeout: 2000,
clip: ‘l2r’
});
});

Reply

John Munoz August 3, 2010 at 9:57 am

Matt,

Great, great, great! I followed instructions for 3 other sliders for Thesis and spent about 7 hours trying to get them to work, but to no avail. I discovered your elegant and simple solution this morning and was up and running in 20 minutes!

One suggestion I’d make. As a noob, I spent about 10 minutes not knowing that I needed to insert em units where the ‘—’ are in the top line of the custom.css. You might want to have defaults in there or comments instructing users what to do.

Thank you Matt. I am donating a beer!

Reply

Matt August 4, 2010 at 11:13 am

Good call! I’ll fix it soon.

Reply

Charles Smith August 6, 2010 at 3:58 pm

Matt:

Seeing that you are the “tutor”, I was hoping you could lend a hand. I would like to add a text resizer button at the top of my content areas, so my older site visitors can enlarge the text if needed. I would love to use Jquery, but have no clue as to where to find the appropriate code, let alone how to add it to my custom_functions file and hooking it into my content_area. Any help from you or your visitors woudl be greatly appreciated. Thank you.

Reply

Kacia @ Coconut Robot August 10, 2010 at 10:24 pm

Hi! I was just wondering if you could shed any light on possible ways to center the jquery slideshow? I’ve read through all of the comments – as I don’t want to waste your time! :O(

Any light you can shed on it would be GREATLY appreciated – i’m assuming i need to fix the padding? but I wasn’t sure where…. thanks!

test.coconutrobot.com –> my playground for hte new http://coconutrobot.com

thanks!
Kacia

Reply

Asif Chowdhury August 17, 2010 at 3:38 pm

Hi,
Thanks for this tutorial. Please visit my blog to see which things I have modified with the help of your tutorials.

Bless you

Reply

Matt August 15, 2010 at 12:48 pm

Not much I can do unless I have access to the site or files. You can email me at thesistutor at gmail dot com with details.

Reply

Leave a Comment

Previous post:

Next post: