Adding a Responsive jQuery Slider to Your WordPress Theme

Adding a Responsive jQuery Slider to Your WordPress Theme

Tutorial Details
  • Difficulty: Intermediate
  • Estimated Completion Time: 30 Minutes

Today I’m going to take you through integrating a responsive jQuery slider into your WordPress theme or site. It’s not a groundbreaking tutorial but it’s one that’s rarely done right, so I’d like to try and fix that. In this tutorial we’re going to cover every step from creating a custom post type to hold our slides, to actually using the slider within our site.

We’re going to be using the lovely FlexSlider 2 by WooThemes as it’s a very well-coded responsive slider that’s licensed under the GPLv2 License. If you’re interested, you can take a look at the code for FlexSlider in its GitHub Repository.

Before we do anything, we’re going to take a step back and think about:

  • What files the slider requires
  • What files we require

The first thing we’re going to do is download FlexSlider.

After you’ve done that, go ahead an unzip it.

There are a few files there we’re interested in, mainly:

  • flexslider.css
  • images/bg_direction_nav.png
  • jquery.flexslider-min.js

They’re all we really need from the FlexSlider download.


Step 1 Setting Up the Files

Let’s move those 3 files from the above into our theme’s directory now. Depending on your theme or set-up you can place the files wherever you’d like, just take note of where those files are sourced/referenced and adjust the code to fit their new location.

For the sake of this tutorial, we’ll be using the default Twenty Eleven theme. In the inc/ directory, create a new folder called slider. In there, let’s create a few folders:

  • css
  • images
  • js

Let’s put flexslider.css in the css folder, bg_direction_nav.png in the images folder and jquery.flexslider-min.js in the, you guessed it, js folder.

Note: Normally I would place these in css/images/js folders throughout the theme’s directory with other files but in order to make this tutorial ‘universal’, we’re organising our files this way. If you’re experienced with WordPress theme development you may want to manually organise your files.

Now we’re going to create 2 more files in the slider folder:

  • slider.php – creates the slider’s template & loads the slider’s files
  • slider_post_type.php – creates the slider post type

You should now have a slider folder that looks something like this:

Before we go ahead, open up your functions.php file and add in the following two lines, which will load the two .php files we just created:

// Create Slider Post Type
require( get_template_directory() . '/inc/slider/slider_post_type.php' );
// Create Slider
require( get_template_directory() . '/inc/slider/slider.php' );

Now… let’s start coding!


Step 2 Slider Post Type

First thing we’re going to do is create a custom post type that will hold all our slides. Custom Post Types were introduced in WordPress 3.0 and are probably the coolest thing to ever happen to the world (too far? I just love them).

Open up slider_post_type.php and add the following code to create the slide custom post type:

<?php

// Create Custom Post Type
	
	function register_slides_posttype() {
		$labels = array(
			'name' 				=> _x( 'Slides', 'post type general name' ),
			'singular_name'		=> _x( 'Slide', 'post type singular name' ),
			'add_new' 			=> __( 'Add New Slide' ),
			'add_new_item' 		=> __( 'Add New Slide' ),
			'edit_item' 		=> __( 'Edit Slide' ),
			'new_item' 			=> __( 'New Slide' ),
			'view_item' 		=> __( 'View Slide' ),
			'search_items' 		=> __( 'Search Slides' ),
			'not_found' 		=> __( 'Slide' ),
			'not_found_in_trash'=> __( 'Slide' ),
			'parent_item_colon' => __( 'Slide' ),
			'menu_name'			=> __( 'Slides' )
		);

		$taxonomies = array();

		$supports = array('title','thumbnail');

		$post_type_args = array(
			'labels' 			=> $labels,
			'singular_label' 	=> __('Slide'),
			'public' 			=> true,
			'show_ui' 			=> true,
			'publicly_queryable'=> true,
			'query_var'			=> true,
			'capability_type' 	=> 'post',
			'has_archive' 		=> false,
			'hierarchical' 		=> false,
			'rewrite' 			=> array( 'slug' => 'slides', 'with_front' => false ),
			'supports' 			=> $supports,
			'menu_position' 	=> 27, // Where it is in the menu. Change to 6 and it's below posts. 11 and it's below media, etc.
			'menu_icon' 		=> get_template_directory_uri() . '/inc/slider/images/icon.png',
			'taxonomies'		=> $taxonomies
		);
		register_post_type('slides',$post_type_args);
	}
	add_action('init', 'register_slides_posttype');

Custom Post Type added! Below that we’ll add the metabox where there’s a field for the URL that the slide should link to. We’re now going to copy the following big wall of code:

// Meta Box for Slider URL
	
	$slidelink_2_metabox = array( 
		'id' => 'slidelink',
		'title' => 'Slide Link',
		'page' => array('slides'),
		'context' => 'normal',
		'priority' => 'default',
		'fields' => array(
	
					
					array(
						'name' 			=> 'Slide URL',
						'desc' 			=> '',
						'id' 				=> 'wptuts_slideurl',
						'class' 			=> 'wptuts_slideurl',
						'type' 			=> 'text',
						'rich_editor' 	=> 0,			
						'max' 			=> 0				
					),
					)
	);			
				
	add_action('admin_menu', 'wptuts_add_slidelink_2_meta_box');
	function wptuts_add_slidelink_2_meta_box() {
	
		global $slidelink_2_metabox;		
	
		foreach($slidelink_2_metabox['page'] as $page) {
			add_meta_box($slidelink_2_metabox['id'], $slidelink_2_metabox['title'], 'wptuts_show_slidelink_2_box', $page, 'normal', 'default', $slidelink_2_metabox);
		}
	}
	
	// function to show meta boxes
	function wptuts_show_slidelink_2_box()	{
		global $post;
		global $slidelink_2_metabox;
		global $wptuts_prefix;
		global $wp_version;
		
		// Use nonce for verification
		echo '<input type="hidden" name="wptuts_slidelink_2_meta_box_nonce" value="', wp_create_nonce(basename(__FILE__)), '" />';
		
		echo '<table class="form-table">';
	
		foreach ($slidelink_2_metabox['fields'] as $field) {
			// get current post meta data
	
			$meta = get_post_meta($post->ID, $field['id'], true);
			
			echo '<tr>',
					'<th style="width:20%"><label for="', $field['id'], '">', stripslashes($field['name']), '</label></th>',
					'<td class="wptuts_field_type_' . str_replace(' ', '_', $field['type']) . '">';
			switch ($field['type']) {
				case 'text':
					echo '<input type="text" name="', $field['id'], '" id="', $field['id'], '" value="', $meta ? $meta : $field['std'], '" size="30" style="width:97%" /><br/>', '', stripslashes($field['desc']);
					break;
			}
			echo    '<td>',
				'</tr>';
		}
		
		echo '</table>';
	}	
	
	// Save data from meta box
	add_action('save_post', 'wptuts_slidelink_2_save');
	function wptuts_slidelink_2_save($post_id) {
		global $post;
		global $slidelink_2_metabox;
		
		// verify nonce
		if (!wp_verify_nonce($_POST['wptuts_slidelink_2_meta_box_nonce'], basename(__FILE__))) {
			return $post_id;
		}
	
		// check autosave
		if (defined('DOING_AUTOSAVE') && DOING_AUTOSAVE) {
			return $post_id;
		}
	
		// check permissions
		if ('page' == $_POST['post_type']) {
			if (!current_user_can('edit_page', $post_id)) {
				return $post_id;
			}
		} elseif (!current_user_can('edit_post', $post_id)) {
			return $post_id;
		}
		
		foreach ($slidelink_2_metabox['fields'] as $field) {
		
			$old = get_post_meta($post_id, $field['id'], true);
			$new = $_POST[$field['id']];
			
			if ($new && $new != $old) {
				if($field['type'] == 'date') {
					$new = wptuts_format_date($new);
					update_post_meta($post_id, $field['id'], $new);
				} else {
					if(is_string($new)) {
						$new = $new;
					} 
					update_post_meta($post_id, $field['id'], $new);
					
					
				}
			} elseif ('' == $new && $old) {
				delete_post_meta($post_id, $field['id'], $old);
			}
		}
	}

Phew. That’s over. Go to your Dashboard and you’ll see a new shiny ‘Slides’ Custom Post Type.


Step 3 Load Slider Files

Open up slider.php. Now we’re going to enqueue jQuery, the FlexSlider jQuery script and the FlexSlider stylesheet. Alternatively you could copy the code from flexslider.css to your style.css file if desired.

<?php

// Enqueue Flexslider Files

	function wptuts_slider_scripts() {
		wp_enqueue_script( 'jquery' );

		wp_enqueue_style( 'flex-style', get_template_directory_uri() . '/inc/slider/css/flexslider.css' );

		wp_enqueue_script( 'flex-script', get_template_directory_uri() .  '/inc/slider/js/jquery.flexslider-min.js', array( 'jquery' ), false, true );
	}
	add_action( 'wp_enqueue_scripts', 'wptuts_slider_scripts' );

While we’re doing this, there’s something you need to do. Due to our file structure, the flexslider.css needs some editing so it knows where to find the arrow image. Open it up and do a search and replace for:

  • images with ../images

Step 4 Initialize Slider

Now we need to add some jQuery to our <head> in order to initialize the slider. Let’s add in the following lines to slider.php below the code we just added!

// Initialize Slider

	function wptuts_slider_initialize() { ?>
		<script type="text/javascript" charset="utf-8">
			jQuery(window).load(function() {
				jQuery('.flexslider').flexslider({
					animation: "fade",
					direction: "horizontal",
					slideshowSpeed: 7000,
					animationSpeed: 600
				});
			});
		</script>
	<?php }
	add_action( 'wp_head', 'wptuts_slider_initialize' );

One of the reasons I chose to use FlexSlider is because of its flexability. There are quite a few parameters you can tinker with, but I just included four important ones above. Try changing slide to fade, or horizontal to vertical. You can take a look at all of the paremeters over here.

Note: Keep in mind that another way to do the above is using the wp_localize_script function (see in Codex) but this is a little bit advanced for this tutorial. However, Pippin Williamson (another Wptuts+ author) has just written an excellent tutorial on the subject if you’re interested.


Step 5 Create Slider

Now we’re going to actually create the template for the slider. First, we’ll do a WP_Query to pull ‘posts’ from the Slides Custom Post Type. Next, we’ll check for slides and if so start the slider. We’ll then start the loop. Each ‘slide’ will then check if a slide URL has been set and if so, create a link for it. The slide’s image will then be displayed and the loop will be closed up.

// Create Slider

	function wptuts_slider_template() {

		// Query Arguments
		$args = array(
			'post_type' => 'slides',
			'posts_per_page' => 5
		);	

		// The Query
		$the_query = new WP_Query( $args );

		// Check if the Query returns any posts
		if ( $the_query->have_posts() ) {

			// Start the Slider ?>
			<div class="flexslider">
				<ul class="slides">

					<?php
					// The Loop
					while ( $the_query->have_posts() ) : $the_query->the_post(); ?>
						<li>

						<?php // Check if there's a Slide URL given and if so let's a link to it
						if ( get_post_meta( get_the_id(), 'wptuts_slideurl', true) != '' ) { ?>
							<a href="<?php echo esc_url( get_post_meta( get_the_id(), 'wptuts_slideurl', true) ); ?>">
						<?php }

						// The Slide's Image
						echo the_post_thumbnail();

						// Close off the Slide's Link if there is one
						if ( get_post_meta( get_the_id(), 'wptuts_slideurl', true) != '' ) { ?>
							</a>
						<?php } ?>

					    </li>
					<?php endwhile; ?>

				</ul><!-- .slides -->
			</div><!-- .flexslider -->

		<?php }

		// Reset Post Data
		wp_reset_postdata();
	}

Step 6 Using the Slider

Well, we’ve finally made the slider! Now it’s time to actually use it. You can open up any template file, such as index.php, and echo the wptuts_slider_template function to display the slider.

So if we wanted to show the slider in Twenty Eleven right after the header on the home page, we would open up index.php and just beneath get_header(); ?>, add the following:

<?php echo wptuts_slider_template(); ?>

But what if you’re making this for a client or someone who just doesn’t want to touch template files and PHP? We should probably create a shortcode for them, so they can just use the slider with a [slider] shortcode.

Add this at the bottom of slider.php:

// Slider Shortcode

	function wptuts_slider_shortcode() {
		ob_start();
		wptuts_slider_template();
		$slider = ob_get_clean();
		return $slider;
	}
	add_shortcode( 'slider', 'wptuts_slider_shortcode' );

The slider can now be used within posts, pages or anywhere else that accepts a shortcode!


Download

If you’d like, you can download the slider folder, which contains everything we went through in this tutorial. You just need to drop it in your theme’s inc folder (or somewhere else is fine, but be sure to adjust the code below) and add the following to your functions.php:

// Create Slider Post Type
require( get_template_directory() . '/inc/slider/slider_post_type.php' );
// Create Slider
require( get_template_directory() . '/inc/slider/slider.php' );

Note: For the sake of this tutorial, the namespace/text domain wptuts has been used. You should do a search and replace on all code if you’re just copying/pasting it and replace:

  • wptuts_ with yourname_
  • 'wptuts' with 'yourname'

If you liked this tutorial, let me know and I’ll continue with a tutorial on customising our slider! We’ll then take a look at using thumbnails for navigation, integrating video slides and adding in captions.

Note: Want to add some source code? Type <pre><code> before it and </code></pre> after it. Find out more
  • Guillaume

    Hum, so you have to create a new post any time you want to add a slide to a slider ? I think you could do simpler. Why not creating a slider post type and use the default media library attached to this post to set slides for the slider ? Would be more convenient don’t you think ?

    Because the way you do, you can only have one slider that lists all slides and display it wherever you want, but what if you want two separate sliders (with different images) or simply choose images you want to show ?

    • bryceadams
      Author

      Hey! I think the way we have it set up with a custom post type for slides and how you add in one slide at a time in the same way that you’d add a post is the simplest way to do it. Mainly because it needs to be a solution that works for a wide range of users and it’s the most flexible.

      I completely agree that it is better to set it up so that the Slider has ‘Categories (or another taxonomy like Slider Types)’, but for the sake of keeping the tutorial a little more accessible and simple I decided to exclude that from it. However, it’s pretty straight forward and basically involves:
      -Changing line 19 of Step 2 to:
      https://gist.github.com/3959063
      -Changing from line 2 onwards of Step 5 to:
      https://gist.github.com/3959059

      Then you can add a specific slide to a category and then display a slider with just slides from that category by using the wptuts_slider_template() function, with $id as a parameter so wptuts_slider_template(’5′) would display slides from the slider category with the the ID 5.

      Of course this could then easily be extended to allow the slider shortcode to display sliders from certain categories too so I may add that bit of code here later too if it’s desired.

      • http://www.facebook.com/agep.rumanto Agep Rumanto

        Yes I am waiting your code for using in shortcode. How to add via shortcode if you have different category id?

        • bryceadams
          Author

          I just threw this together but it should work. Don’t use the shortcode code above but use this instead: https://gist.github.com/3962418

          And then you can do [slider id="5"] etc. to show sliders based on that ID. :)

          • http://www.facebook.com/people/Fala-Do-Jogo/100003754714627 Fala Do Jogo

            doesnt work for me with an id, no images shown.

      • Sacha Benda

        Hi Bryce,

        adding ‘category’ in the support array doesn’t work for me.

        I checked in the codex and there is no reference to this.
        (http://codex.wordpress.org/Function_Reference/register_post_type)

        I tried by adding a custom taxonomy and it works, but am still wondering if I am doing something wrong. Your solutions is much simpler…

        • bryceadams
          Author

          Hey Sacha. In line 19 on Step 2 you should see where we defined the $supports variable. You just need to add it in there. If you swap line 19′s code with the code from here: https://gist.github.com/3959063. it will definitely add it. Taxonomy works fine too.

          If it’s not working when you add it in on line 19, there must be a typo or some other option set that’s conflicting with what we’re defining. I’d stick with taxonomy if you can’t find the cause.

  • http://twitter.com/cramdesign matt cram

    categories would be a nice addition so that you could create different sliders. Nice work though.

    • bryceadams
      Author

      Thank you! Agreed with categories addition but I wanted to keep the tutorial accessible and simple. However I went ahead and provided a solution on how to add category functionality below :)

  • Giuseppe Frattura

    Sorry but i didn’t understand how can i add images to the slider.
    Thank you!

    • http://twitter.com/zzap_m Milana Cap

      You add images via featured image as the post type supports it.

      • bryceadams
        Author

        Yep, as Lawrence and Milana said, you add the slides image using the ‘Set Featured Image’ box, and then upload the image and set it as the featured image.

        Now if you’re doing this for a client or a theme, it probably makes sense to change the title of the Featured Image box to something like ‘Slider Image’. I actually wrote a short article on this a while back that explains just how to do that: http://bryceadams.com/change-title-of-wordpress-meta-boxes/ (ask Questions about that there).

        Thanks for reading!

      • LandonAB

        @Milana Cap After going through the code over and over for 3 days, you pointed out the obvious and now it works. Dammit! :) Thank you!

      • http://www.facebook.com/eugenio.palazzi Eugenio Palazzi

        I don’t have the featured image box. do you know why?
        thanks.

        • bryceadams
          Author

          It should be there. Try add:
          add_theme_support( ‘post-thumbnails’ );
          to your functions.php

    • lawrence77

      You can set featured image for slider’s image.

  • http://www.facebook.com/people/Niculae-Bucur-Ion/100000399490380 Niculae Bucur Ion

    Uau veri nice job,thank you very much for this tutorial…

  • Pingback: Adding a Responsive jQuery Slider to Your WordPress Theme | qoozon

  • Pingback: Adding a Responsive jQuery Slider to Your WordPress Theme | qoozon

  • http://twitter.com/deifosv Vladimir Palacio

    this is great! thank you so much for this Bryce, this helps me so much you cant imagine, I’m a web design beginner and I love getting my hands dirty doing all this, please continue with the customization of the slider, thumbnails navigation, I cant wait!!!

    Once again, thank you!

    • bryceadams
      Author

      Thanks Vladamir :) Following the tutorials on Wptuts+ is a great way to get started so stick around and you’ll be writing them yourself soon enough! And it’s no problem – I’m just glad to help!

  • http://twitter.com/kevinbatdorf Kevin Batdorf

    Just as an alternative, the Liquid Slider (by me) is another open source option, which can take any html content, not just images. http://liquidslider.kevinbatdorf.com/

    • http://www.facebook.com/people/Niculae-Bucur-Ion/100000399490380 Niculae Bucur Ion

      very nice job man…

  • Nuruzzaman Sheikh

    very lovely and to the point tutorial. Great Reading :P

  • Nixy

    Awesome man..Keep up the great work…I am eagerly waiting as to how
    can we customize the slider..Also it would be great if you can write an
    in-depth article about creating a JQuery Mobile based wordpress theme..I
    have searched a lot on net and I got a few, but not anything great..So
    if you can write one, it would be very helpful

    • bryceadams
      Author

      Cheers Nixy! Good idea. I’ll see what I can do :)

  • http://sharecodeweb.com/ Share code web

    Good Article. Thank for share

    I will try doing it with my blog

  • http://www.facebook.com/sam.abouna.35 Sam Abouna

    Good article but I honestly can’t stand the way that code is displayed on your site with a horizontal scrollbar. Not exactly user friendly or best practice. There’s a lot other small design blogs and they display the code in a much better way, not sure why this is such an issue for you guys to fix. Otherwise thanks for the article.

    • bryceadams
      Author

      Yeah of course, but don’t be afraid to just try. I didn’t even know what jQuery was 6 months ago yet alone enqueueing of scripts/styles, PHP, etc.

      An easy way to implement this though is just downloading the source files, putting it in your theme’s INC folder (or creating it if it’s not already there), adding the few lines as explained at the end of the tutorial to your functions.php file and then just use it! :)

      • http://www.facebook.com/sam.abouna.35 Sam Abouna

        Thanks Bryce! I actually typed out all the code so I could get more of a grasp for it but I will definitely used it on my next theme!

  • Pingback: اضافه کردن یک اسلایدر Responsive به پوسته وردپرس | Design Tutorials | طرّاحی وِب و گرافیک

  • LandonAB

    How is this changed when using a child theme? After adding the first step in functions.php in my child theme my site only displays a white page. Thanks!

    • bryceadams
      Author

      Hey Landon. I should have mentioned that if you’re doing this through a child theme, the get_template_directory function will look in your parent theme’s directory. You’ll need to use get_stylesheet_directory as explain here: http://codex.wordpress.org/Function_Reference/get_template_directory

      • LandonAB

        Thank you, will check it out!

      • LandonAB

        Yes, that fixed the white page. Thanks again. I am trying to learn as much as I can about WordPress but presently only scratching the surface.

        Appreciate the site!

  • LandonAB

    Looks like I am still missing something. If any one has a second, would appreciate a suggestion.

    http://lab72.dev4.webenabled.net

    Thanks!

    • LandonAB

      I have been over this multiple times, even just added the files directly from the download and still I have the slider on the page but no images. I can’t figure out why they will not display.

      • LandonAB

        I did not realize I had to set a featured image, I was pasting the image URL in and that was all. Now it works.

        Maybe add the final steps to the end of the tutorial for us that are too dense to figure this bit out :)

        • bryceadams
          Author

          Sorry for the confusion! Glad to hear you got it working.

  • Pingback: Slider jQuery responsive wordpress - CodesScripts

  • Kim Spillner

    Thanks,this is a really great article.

    I personally think it would be much more accessible to use the media uploader instead of copying and pasting the slide img url.

    • bryceadams
      Author

      Hi Kim! You do use the media uploader. It’s the only way to upload your slides. You click featured image and set the slide through the media uploader there, just like you would for a post.

      The URL Box is for setting the slide’s link – which page you want the slide itself to link to when clicked on. Sorry for not being clearer.

      • Kim Spillner

        Thanks for the info Bryce,
        I have another Problem now though. If I set the featured article image it alway takes the thumbnail picture which is small and square and stretches it over the whole screen.

        Any suggestions?

        • bryceadams
          Author

          What you should do is add_image_size (codex.wordpress.org/Function_Reference/add_image_size) for the size you’d like your slides to be, and then in step 5 on line 24, change :
          echo the_post_thumbnail();
          TO
          echo the_post_thumbnail(‘name-of-the-new-image-size’);

          • http://www.facebook.com/david.sinjaya David Sinjaya

            Hi bryceadams,

            thank you for the great article. However, I could not resize the thumbnail. I added
            “add_image_size(‘slider_image’,400,300);” in slider.php and replace

            “echo the_post_thumbnail();” TO “echo the_post_thumbnail(‘slider_image’);”.

            These changes allows the picture shown in real size, instead of expected size. Any changes that I made in adjusting image size did not change anything. Any suggestions?

            I am looking forward for the next tutorial which explains how to add a caption :)

          • Sacha Benda

            Remeber that when you set a new image size all the images in the media library need to be regenerated. Otherwise the news size will be generated only for the newly uploaded images.
            There is the wonderful plugin from one of the WP developers: Alex Mills – http://wordpress.org/extend/plugins/regenerate-thumbnails/

  • andy

    yeah, be nice if you told us what exactly you were doing along the way and why, otherwise we learn nothing.
    wp.tutsCOPY+PASTEplus

    • bryceadams
      Author

      Hi Andy. Sorry, I thought I was more clear. I’ll definitely take this into consideration in my next tutorial. Thank you.

  • http://twitter.com/0xAgeng Ageng J

    sorry my image no show

  • disqus_BMYiquf8wO

    What about adding caption?

    • bryceadams
      Author

      Hey! This tutorial was getting pretty lengthy so I left that out but it’s planned for a future tutorial, along with thumbnails/videos/etc. :)

      • Ann

        Hey! Thanx for cool tutor! How about next tutor?

  • apsolut

    not shure why, but i get

    Notice: Undefined index: std in /home/public_html/wordpress/wp-content/themes/blacktheme/inc/slider/slider_post_type.php on line 103

    and

    Notice: Undefined index: wptuts_slidelink_2_meta_box_nonce in /home/public_html/wordpress/wp-content/themes/blacktheme/inc/slider/slider_post_type.php on line 120

    • bryceadams
      Author

      Hey Apsolut. Not sure about these but they are just Notices, and won’t display on the production version of your site unless you have notices displayed. Talk to your hosting support or google removing PHP notices. :)

    • VuzzThemes I

      Errors shouldn’t be there, hidden or not. You might want to have a look at some projects for custom metaboxes and fields for wordpress on Github, it could be helpful.

    • Konstantin

      I have the same problem, if WP_debug is enabled. Without WP_debug it works normally

  • Pingback: Die besten meiner geteilten Links auf Twitter im Oktober 2012 | pixelstrol.ch

  • Pingback: Adding a responsive JQuery slider to your wordpress theme, JDS WebDesign Word Press Tutorial

  • phuc doan

    I tried to insert the images through set featured image box, but could not get the images to the slider. Can you be more specify at the section?
    Thank you.

    • bryceadams
      Author

      Hey! If you set your image as the featured image it will display. Please see earlier comments on this

      • phuc doan

        Thanks! It was so simple.
        I have a question. In slider.php file, when we init the slider using jquery selector, I modify jQuery(window)… to $(window) then it does not work anymore. I don’t understand it because jQuery() and $() are the same. I’m still new in WordPress so is there anything tricky about this?

        • bryceadams
          Author

          This is to do with WordPress using a copy of jQuery that’s in ‘compatibility mode’. But, you can still use $ (instead of jQuery), you just need to wrap it in a function. Have a read of this http://digwp.com/2011/09/using-instead-of-jquery-in-wordpress/ (I also go a little further into it in my next Wptuts+ article coming soon)

          • phuc doan

            Thank you so much! I got it clear now. Waiting for your next Wptuts :)

  • SarahlMorrow

    I recently just made one of these, but I’m wondering how this would work if you were to also include content — how would that adjust to become responsive with an image?

    • bryceadams
      Author

      It would really depend on the content regarding the responsiveness. Just give it a go and see how it works out :)

  • http://www.facebook.com/sam.abouna.35 Sam Abouna

    I want to use this on a theme I’m making and I’m trying to figure out how I would only display the slider on the homepage. I know I’m going to have to use a conditional but just need some help to get the ball rolling. Any tips or hints would be appreciated, thanks!

    • bryceadams
      Author

      There are a few ways. You could add it in your header.php like – https://gist.github.com/4030268

      Or the BETTER way is to create a page template ( http://codex.wordpress.org/Pages#Page_Templates ), make a page with that template, set that page as your home page in Settings > Reading Settings and include the slider in the page template (with the shortcode or PHP in the template file).

  • Makaö

    Hello.

    This is a good tutorial. I’ve been customizing a theme I found on the internet. It has a Flash slider which I would like to get rid of and replace with the Jquery one. However, after following your instructions, my website gets completely messed up. I mean, the dashboard wont even load anymore (shows a white page) and the front page of my wordpress blog is completely messed up. (I did get rid of the flash slider, though lol) Now, Im not a expert with this kind of stuff so Im a bit lost. The theme Im using is called “peacekeeper” (http://www.web2feel.com/peacekeeper/). I’m trying to replace the slider call in header.php:

    ?php include (TEMPLATEPATH . ‘/slide.php’); ?

    with…

    ?php echo wptuts_slider_template(); ?

    I know there must be something else I need to do to get it to work, but I’m not sure what.

    Any help is appreciated. :)

  • Pingback: Adding a Responsive jQuery Slider to Your WordPress Theme | billybacklinks.com

  • http://www.facebook.com/eugenio.palazzi Eugenio Palazzi

    i have a problem: I don’t have the featured image box in the slider panel; how is this possible?
    thanks for your help.

    • Edgarr

      It might be hidden, click on the “screen options” tab on the top right corner of your screen while editing your post, and make sure the “featured image” option is checked

      http://en.support.wordpress.com/screen-options/

      • bryceadams
        Author

        Edgarr has a good point, it may be hidden. Otherwise I replied to you above

  • http://www.facebook.com/eugenio.palazzi Eugenio Palazzi

    I’m trying to add the slider in my own theme but in the slider panel I don’t have the featured image box.
    Can someone help me? may I need to buy the WooSlider plugin.

    • http://www.facebook.com/eugenio.palazzi Eugenio Palazzi

      solved! IForgot this add_theme_support(‘post-thumbnails’); in functions.php

  • Денис Черников

    Hello!
    Tell me what’s wrong!
    Did as you have on the home page sliders appear, but there is no picture?

  • Pingback: Add a Responsive Lightbox to Your WordPress Theme | Wptuts+

  • Pingback: Add a Responsive Lightbox to Your WordPress Theme | Wordpress Webdesigner

  • bryceadams
    Author

    Just a note on this tutorial. I turned the basic slider that we built here into an awesome free plugin that you can download (if the tutorial is too hard to follow). It has a few more features that I’ll be explaining how to integrate yourself in a future tutorial: wordpress.org/extend/plugins/captain-slider/

  • Pingback: themeshift | CMS Radar

  • http://www.facebook.com/cgdfs Aqeela Sadaf

    hi. . .Beyce m new to wprdpress, m stuck in step four :( , in which file the section is so i can add that code. . . help me…..

  • http://www.facebook.com/cgdfs Aqeela Sadaf

    by following your post till step 3, it gives me following warning when i goto dashboard .. .
    Warning: Invalid argument supplied for foreach() in E:xampphtdocswordpresswp-contentthemestwentyelevenincsliderslider_post_type.php on line 62

  • Bilal Ameer

    I just get files and place it in “inc” folder, then make edit function.php file as you mention in last. And call wptuts_slider_template() in home.php after header.
    Now adding a new slide with correct Slide URL, when go to display the effect, its just showing a white bar and and the code behind is just

    Can you tell me the mistake, if I make??
    Why its not displaying?

  • jordon

    I recently did this tutorial and nothing shows. Up. I tried switching my files out with the sample files as well. That did not work either. I have the phpto the index.php file as well.I added the code to the functions.php file.I have checked the directory path and still no slider is showing up. Any ideas?

  • ashok

    i have downloaded the above slider and follow all the instructions which mentioned above….but i am not able to activate this slider on my wordpress theme……it still is showing default slideshow……what should i do ???

  • http://www.facebook.com/people/Fala-Do-Jogo/100003754714627 Fala Do Jogo

    Hi. categories are not working for me after I made those changes! without categories this is not very usefull. Also, when i resize the browser, images do not adjust vertically, its stays always 400px! anyone knows why?
    Another thing, how can I add the content box and use it as caption?

    Thanks a lot for this tutorial!

  • http://digitalrenewal.com Trisha Dingillo

    I encountered 2 problems with the code, otherwise, it worked quick and easy!

    changed the css style – .flexslider .slides img {width: 100%; height:100%; display: block;} (added height)
    in slider.php changed – animation: “slide”, (fade didnt work, blew out the height)

    hope it helps!

  • http://www.etatvasoft.com/php-web-services/wordpress-development.php AliBarker

    I wanted to thank you for this great read!! I definitely enjoying every little bit of it I have you bookmarked to check out new stuff you post.

  • limecanvaswil

    HI there. When I remove the 4px solid border from the .flexslider class, it throws the slides about 25% to the right of the viewport.

    Also – when I change the animation type to “slide” it doesn’t appear to fit the width of the content box.

    Anyone know why?

  • Lowlow

    Hi everyone,
    Such a great tutorial !! Thank you !! But I ve a question :

    How do you adjust the size of the slider ?

    • Lowlow

      I’ve found it. It was in the flexslider.css !!

      But how should I do if I want to do a second slideshow ? Slides are for one slideshow but if I want to do another one on a new page ?

      • Macauley Dallas

        What did you do?

  • http://www.facebook.com/david.dvor David Dvoř

    hi… i add slider in to the theme but it´s show me error

    Warning: Invalid argument supplied for foreach() in /var/www/web5/mypixel.cz/mypixel.cz/wp-content/themes/minecraft/admin/slider/slider_post_type.php on line 73

    for this peace of code

    add_action(‘admin_menu’, ‘minecraft_add_slidelink_2_meta_box’);

    function minecraft_add_slidelink_2_meta_box() {

    global $slidelink_2_metabox;

    foreach($slidelink_2_metabox['page'] as $page) { //line 73

    add_meta_box($slidelink_2_metabox['id'], $slidelink_2_metabox['title'], ‘minecraft_show_slidelink_2_box’, $page, ‘normal’, ‘default’, $slidelink_2_metabox);

    }

    }

  • http://www.facebook.com/sonalmac Sonal Patelia

    I tried to work on this, along with child theme. Child folder theme is in content folder only. But I get this error:

    Fatal error: Call to undefined function add_action() in C:xampphtdocswordpresswp-contentthemestwentytwelvechildincsliderslider.php on line 11

    I searched online for it, and it says that the script is running before wordpress_load function. But I don’t find solution for this. What can I do?

    • http://www.facebook.com/sonalmac Sonal Patelia

      I got something to work with. In functions.php file, I had to use

      require(dirname(__FILE__) . ‘/inc/slider/slider_post_type.php’);

      require(dirname(__FILE__) . ‘/inc/slider/slider.php’);

      However, I’ve got a new problem. The slider images shows up like below the footer. They don’t shows up just below the header.

  • http://www.facebook.com/sonalmac Sonal Patelia

    Doesn’t it suppose to show only on the page we are linking that slide show? I see it coming up on every page of the site and also the images are showing below the footer. Any insight? thanks..

  • http://www.facebook.com/nathan.bustermente Nathan Bustermente

    Hi, i have installed all files, slider box shows up but not the images which i set to the feature image?

  • http://www.facebook.com/emil.wagenius Emil Wagenius

    Can you please help me? I get the following error after adding the code to the functions.php file:

    Warning: Cannot modify header information – headers already sent
    by (output started at
    /home/hiphop/public_html/beta/wp-content/themes/tihhm2013/functions.php:6)
    in /home/hiphop/public_html/beta/wp-includes/pluggable.php on line 876

  • livingaudio

    The slider works great at full frame except when I shrink the window, I don’t know where it’s calling the height constraint for the image because it distorts the smaller it goes.

  • Pingback: » WordPress Theme – Studio Box Premium WordPress Theme Resell Rights|Resale Rights|PLR Resources

  • Pingback: » WordPress Theme – Studio Box Premium WordPress Theme Free WordPress Themes| Free WordPress Templates

  • Pingback: 20 Useful WordPress Theme Tutorials and Resources - Streetsmash

  • Me

    Thankyou for this awesome lesson.
    I like how u end this tutorial with a adventure time picture :D

  • Spacechimp

    Hi Bryce,

    Thanks for the Tutorial – Absolutely brilliant. I’ve managed to follow your instructions and get Categories working although I did it slightly differently i actually changed line 21 in slider_post_types.php to :

    $taxonomies = array(‘category’);

    rather than adding ‘category’ to the $supports array. What i’d like to do is add a custom taxonomy.

    I’ve replaced the taxonomies array with :

    $taxonomies = array(‘category’,'slideshow’);

    and added this to my custom functions.php

    function build_taxonomies() {
    register_taxonomy(
    ‘slideshow’,
    ‘slides’,
    array(
    ‘hierarchical’ => true,
    ‘label’ => ‘SlideShows’,
    ‘query_var’ => true,
    ‘rewrite’ => array( ‘slug’ => ‘slideshow’ )
    )
    );
    }

    but it’s still not showing, what am i doing wrong?

    Many Thanks in advance

  • Macauley Dallas

    how do I increase the size?

  • http://about.me/jeffgates Jeff Gates

    Is it possible to have some html text under each slide?

  • http://www.facebook.com/mateusz.winnicki.77 Mateusz Winnicki

    Hey !

    How can i change pagination for arrows next back ?

  • brubinstein

    Hi. I’m using this with the Twenty Twelve theme, and getting a nicely shadowed but empty box. Console error message reads Error: TypeError: jQuery(…).flexslider is not a function. It’s pointing to a block in the source code that reads jQuery(window).load(function() {

    jQuery(‘.flexslider’).flexslider({
    animation: “fade”,
    direction: “horizontal”,
    slideshowSpeed: 7000,
    animationSpeed: 600
    });
    });

    Any suggestions?

    Thanks!

  • Guest

    Wouldn’t it be better to use get_stylesheet_directory_uri() instead of get_template_directory, in case you are using a Child theme?

  • Amanda Dominy

    Wouldn’t it be better to use get_stylesheet_directory_uri() instead of get_template_directory(), in case you are using a Child theme?

  • Marko

    Hi. Can somebody help me with loading problem of slider images. I downloaded source files to my computer, and extracted to custom theme (inc folder od my wordpress theme). I placed initialize slider srcipt using
    , but there is a blank (white) space on slider place, like slider border. There is no images, but in source code of my page is code of images. I used in theme header.php and add_theme_support( ‘post-thumbnails’ ); in function.php. Can somebody help me with these? Thx in advice.

  • Pingback: Custom Content types, Downloads, Links, Sliders, Featured Sliders within wordpress | Serverhash Networks

  • Walker Talker

    Hi, thanks for this post. Do you know by any chance how to incorporate some free source sliders, for example http://www.sequencejs.com/. I’ve been trying for days but without good results. Thanks

  • Walker Talker

    Great tutorial. Does anyone know how to arrange slide load order. By default it plays last slide created as a first slide.. Thanks

  • Pingback: اضافه کردن یک اسلایدر Responsive به پوسته وردپرس | Design Tutorials | طرّاحی وِب و گرافیک

  • http://twitter.com/DavidGaryPepper David Pepper

    Hey, nice tut! Just one problem, when I added more than one slide, it appears to load the images on top of each other (see the screenshot). Any idea why this is happening? Many thanks in advance! :-).

  • http://twitter.com/Pyorban Pierre-Yves Orban

    Great tutorial ! Thank you !