Create a Responsive Slider Plugin With FlexSlider for WordPress

Create a Responsive Slider Plugin With FlexSlider for WordPress

Tutorial Details
  • Version (if applicable): 2.9+
  • Program: WordPress
  • Difficulty: Moderate
  • Estimated Completion Time: 30 minutes

Sliders seem to be all the rage these days, and for good reason! You can add photos, content, videos, and more to an eye-catching, animated area of your website. While there is a wealth of slider plugins out there (my current favorite is the one for Nivo Slider), there is not one for FlexSlider, a slider that has keyboard shortcuts and works with swipe on touch screens. In this tutorial, we’ll create that plugin!


Step 1 Plugin Setup

The first thing we need to do is set up the plugin. Create the folder /envato-flex-slider/, and in it, a file called ‘envato-flex-slider.php’. Here we will add all of the necessary information and code for our plugin, starting with the plugin definition block:

<?php

/*
Plugin Name: Envato FlexSlider
Plugin URI: 
Description: A simple plugin that integrates FlexSlider (http://flex.madebymufffin.com/) with WordPress using custom post types!
Author: Your Name
Version: 1.0
Author URI: Your URL
*/

?>

I also like to set up some constants for information I’ll be using a lot throughout the plugin. Under the definition block, but before the closing php tag, I add this info:

define('EFS_PATH', WP_PLUGIN_URL . '/' . plugin_basename( dirname(__FILE__) ) . '/' );
define('EFS_NAME', "Envato FlexSlider");
define ("EFS_VERSION", "1.0");

I create three constants: the plugin’s path, the plugin’s name, and the plugin’s version, which is used for upgrades, and to notify the WordPress Plugin Directory of changes, if needed. Notice I start all of my constants with “EFS.” I’ll do the same thing for function names so that we don’t create a conflict with other plugins or the WordPress core.

Now that we have the setup done, let’s add in the FlexSlider files & code.


Step 2 Adding FlexSlider

It’s time to add the important part: the javascript & CSS for FlexSlider. We’ll do this using WordPress’ wp_enqueue_script and wp_enqueue_style to avoid conflicts. You can download FlexSlider here. We will need 2 files: jquery.flexslider-min.js, and flexslider.css, and the /theme/ folder.

wp_enqueue_script('flexslider', EFS_PATH.'jquery.flexslider-min.js', array('jquery'));
wp_enqueue_style('flexslider_css', EFS_PATH.'flexslider.css');

In both lines, we assign a name to each script, then link to the .js and .css files. Notice we are using our constant ESF_PATH. We need to use the whole path or the files won’t be linked to properly. You’ll also notice that we have a 3rd parameter in wp_enqueue_script. This is an array of other scripts our script depends on. In this case, it’s only one, and it’s JQuery. Here is a full list of scripts included with WordPress. You can use any handle in the dependencies array.

The next thing we want to do is include the actual JavaScript that will make the slider work. We do this with our own function and a WordPress Action.

function efs_script(){

print '<script type="text/javascript" charset="utf-8">
  jQuery(window).load(function() {
    jQuery(\'.flexslider\').flexslider();
  });
</script>';

}

add_action('wp_head', 'efs_script');

The important line here is add_action('wp_head', 'efs_script');, which will run our function, efs_script() when wp_head is called. Our function simply prints the required JavaScript to make FlexSlider do its thing!

You’ll notice that I’m using ‘JQuery’ instead of the traditional ‘$’ usually used in JQuery scripts. This is so our script does not conflict with other JavaScript libraries, like Scriptaculous.

Finally, just copy the /theme/ folder into your /envato-flex-slider/ folder.


Step 3 The Shortcode and Template Tag

Next up, we’re going to set up our shortcode and template tag. The shortcode will allow users to insert the slider into any page or post. We have a really nice introduction tutorial on shortcodes here. The template tag will allow theme developers to insert the slider right into their themes. As a theme developer myself, I think it’s incredibly important to include both, and to make them easy to find in documentation. You never know who’ll be using your plugin.

function efs_get_slider(){

//We'll fill this in later. 

}
/**add the shortcode for the slider- for use in editor**/

function efs_insert_slider($atts, $content=null){

$slider= efs_get_slider();

return $slider;

}
add_shortcode('ef_slider', 'efs_insert_slider');
/**add template tag- for use in themes**/

function efs_slider(){

	print efs_get_slider();
}

Right now this code look pretty simple. For the shortcode, we call our general function, efs_get_slider() and return the results. For the template tag, we print the results. We also use WordPress’ add_shortcode() function to register our shortcode. I’ve purposely left out the implementation of efs_get_slider() because we haven’t set up how we’re going to do the images yet. To make it easy for users to add any number of images to their slider, we’re going to create a custom post type.


Step 4 The Slider Image Custom Post Type

The first thing we’ll do is create a new file called ‘slider-img-type.php’, where all of our code for the custom post type will go. First, we’ll do some set up like we did for the plugin.

<php
define('CPT_NAME', "Slider Images");
define('CPT_SINGLE', "Slider Image");
define('CPT_TYPE', "slider-image");

add_theme_support('post-thumbnails', array('slider-image'));
?>

As you can see, all I’ve done so far is create some constants (which would come in handy for more advanced custom post types), and added thumbnail support for our new type. The only other thing we’ll do in this file is register the new custom post type. For more on custom post types, you can see my tutorial on making a killer portfolio. Right before the closing php tag, we’ll add this code:

function efs_register() {  
    $args = array(  
        'label' => __(CPT_NAME),  
        'singular_label' => __(CPT_SINGLE),  
        'public' => true,  
        'show_ui' => true,  
        'capability_type' => 'post',  
        'hierarchical' => false,  
        'rewrite' => true,  
        'supports' => array('title', 'editor', 'thumbnail')  
       );  
  
    register_post_type(CPT_TYPE , $args );  
}  

add_action('init', 'efs_register');

We’ve created a function to register a custom post type that uses the title, editor, and thumbnail boxes. Then we add a WordPress action to call that function as soon as WordPress is initialized. That’s it! The last thing to do is include our new file by adding require_once('slider-img-type.php'); to envato-flex-slider.php. I added it right above where we enqueue our scripts.

Now that we know the how we’re implementing the slider images, let’s go back and fill in our general function for the slider.


Step 5 Generating the Slider

Head back to where we defined efs_get_slider() and replace the comment //We'll fill this in later with the following:

$slider= '<div class="flexslider">
	  <ul class="slides">';

	$efs_query= "post_type=slider-image";
	query_posts($efs_query);
	
	
	if (have_posts()) : while (have_posts()) : the_post(); 
		$img= get_the_post_thumbnail( $post->ID, 'large' );
		
		$slider.='<li>'.$img.'</li>';
			
	endwhile; endif; wp_reset_query();
	$slider.= '</ul>
	</div>';
	
	return $slider;

The first two lines are needed because of how FlexSlider works. It will look for an unordered list called ‘slides’ within a div called ‘flexslider’ and apply the javascript/animations to that. Our CSS is also set up to define .flexslider and ul.slides. After that, we create a WordPress loop grabbing all of the posts of type slider-image (our custom post type) and we get it to print the large version of the featured image. We then return all of the generated HTML as a variable, which can be printed, as with our template tag, or returned, as with our shortcode.

A Couple of Notes

  • With our custom post type, we can add a title, and featured image, and we’ve included the post editor box. While right now we only use the featured image (and title for the alt text), we’ve included the editor if, for instance, in the future we want to support captions on the slider.
  • When adding a new Slider Image, we must upload a featured image for the slider to work. It will not just grab the post attachment.

Step 6 Testing it Out

Now it’s time to test! Once you add a couple of images to your new custom post type, create a new page (I just called mine Slider) and add our newly created shortcode, [ef_slider]. Save the page and view it. You should see something like this:

Conclusion

That’s about it for now. There are definitely a few things we can do to improve upon the plugin, like add options support for the advanced customizations FlexSlider has to offer or adding caption support. That being said, this plugin gives you everything you need to make a fairly simple, easy to manage, easy to insert version of FlexSlider for WordPress! If you’re unsure about placement or the files to include, you can download the source files using the link at the top of the tutorial. Enjoy!

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

    Is there a demo page available to see the ending result?

    • http://record-shops.org Ingvi Jónasson

      http://flex.madebymufffin.com/

      This is the link to the orginal plugin.

    • Brandon Jones

      Correct – in lots of cases, it’s nearly impossible to set up demos for each of these tutorials because it’d require a unique installation of WP to create a test environment, but we always try to at least provide an HTML or screenshot example :)

      • http://wolfiezero.com/ Neil Sweeney

        Would it be worth looking at doing a WordPress Multi-Site installation to do the majority of WordPress demos?

  • Farzad

    Hi

    Thanks for this great tutorial, was wondering if it’s possible to add thumbnails at the bottom of the slider, I mean can we create a cache folder within the slider plugin directory and automatically create thumbnails for each featured image that we add?!

    If so, then what about when a particular slide has been deleted along with its associated image, then we no longer need to have a thumbnail of that specific featured image, so need to get rid of it, so how could we add a such additional features to this thing?

    Cheers

    • Brandon Jones

      Hi Farzad, that’s not a feature that’s included in the FlexSlider at the moment (I’m not sure if there’s a plan to integrate thumbs yet), which is why it’s not included here. Can you add thumbs? Probably, but it’s require customizing the actual plugin, which goes beyond the basic WP integration :)

      • http://onemaggie.com Maggie

        Flexslider 2.0 does include that functionality afaik

        • http://www.banyanstudio.net Miguel

          I am using Flexslider 2.0 but I can’t seem to get the thumbnails to show. I can “see” the html for the thumbnails using FireBug, but the actual thumbs are not loading.

          For the active slide for example

          img class=”flex-active” src=”undefined”><

          Does anyone have any insight on this?

          Thanks!

  • http://www.christopherguitar.net/wordpress/ Chris

    Easier plugin url:
    define( ‘EFS_PATH’, plugin_dir_url( __FILE__ ) );

    • http://www.casabona.org Joe Casabona
      Author

      Thanks Chris! I’ve been using my same simple framework for a while- I guess it’s time to update!

  • http://techsloution4u.com/ Maidul

    Great tutorial!
    May be its will be more user friendly if we use metabox for image upload and another box to link that url

    • Brandon Jones

      Thanks Maidul, I’ll actually be releasing a customized followup to this one using OptionTree to handle the slide management, so that kind of stuff is coming soon :)

  • http://www.firstlightwebdesign.net Shane Barnes

    Really loving this new site and all the great tutorials that have appeared here so far, this one included. I’m wondering if anyone might suggest a way I can use this plugin to display single posts as though they were chapters in a book. I’m working on a book style theme at the moment and would love for users to be able to click through each post/chapter in a without a page refresh. Anybody have any ideas?

    • http://www.casabona.org Joe Casabona
      Author

      FlexSlider may actually be a reasonable implementation, depending on what you do. I would, however, recommend making each page in the chapter a slide and each chapter it’s own page, so users can like to specific chapters.

      This could also be a good way to go since it works well on touch screens.

  • Steven

    Great Tutorial! Thanks!

  • Lou

    I am surprised and glad to see this tutorial only because I created a similar plugin using FlexSlider for a client website about 2 weeks after FlexSlider was published, and was asked by the author not to make the plugin public… but he would appreciate if I just sent the plugin files…

    • Brandon Jones

      Really? That’s strange… being that the FlexSlider is an open source plugin ;)

      • Lou

        Yeah, I thought it was strange too, I read the license over and over, but since Tyler did create it, I decided to respect his wishes, I still have his email response asking me to refrain from making the plugin available to the community, either way, it’s a sweet slider.

  • kostas

    Awesome tutorial!
    Just one question, please.
    Is it possible to call the flex slider to header.php?
    Any help?
    Thanks in advance!

    • http://www.casabona.org Joe Casabona

      Yup! We’ve actually created a template tag too, called efs_slider(). So in the header you’d just put:

      if(function_exists(‘efs_slider’)){ efs_slider(); }

      • kostas

        Thank You So Much Joseph!

      • Razorback

        For me it ouputs nothing….

        • http://www.jazzcake.com Lionel Douglas

          Dont forget to add the php code part between Joe’s code, thus:
          <pre name="”…. works for me :)

      • Daniel

        Thanks for the best tutorial ever, great slider.

        I am too having problems to implement this in the header.php, I want it to be right under the nav bar of my theme and tried both the short code and calling the function as you mentioned above but the first show nothing and the second just outputs the code as it is. Any suggestions? The slider workrs fine in pages and posts.

  • splitline

    Hello,

    Thanks for the information. I’m new to plugins at the moment.. Everything was very clear except at the very end on step 6 where you say to add our newly created shortcode, [ef_slider].. Where does that part go?

    To me it would seem easier to just add the slider script directly with out adding it as a plugin.. I’m not really see the point of plug-ins.. (from a developer point of view..) Adding it as a plugin does not seem very simple I mean your adding lots of code. I’m new to WordPress at the moment so please bare with me. I’ve developed CMS mostly from scratch.

    • splitline

      Ok now that I have gone over short codes i see whats going now. Sorry about that.

  • Eric

    Hi thanks for this tut, looks promising. I’ve seen elsewhere that when Flexslider is implemented in WP, it doesn’t seem to be responsive.

    Can someone confirm that this indeed is a responsive solution? Otherwise, I’ll stick with Nivo, which is currently working fine, but non-responsive.

    Thanks!

    • Kyle

      I am also having some issues with this as well – I believe it’s because WordPress puts pixel dimensions of images automatically, but do not know how to change/fix this. Any help would be greatly appreciated

      • Kyle

        Well it looks like I should have kept reading….adding this to your CSS works. Thanks James

        img.wp-post-image {
        height: auto;
        width: auto;
        }

        • http://www.markus-schober.at Markus

          Or you can remove your image dimensions:

          function remove_thumbnail_dimensions( $html, $post_id, $post_image_id ) {
          $html = preg_replace( ‘/(width|height)=\”\d*\”\s/’, “”, $html );
          return $html;
          }
          add_filter( ‘post_thumbnail_html’, ‘remove_thumbnail_dimensions’, 10, 3 );

          This worked for me. But this will remove the image dimensions on all post thumbnails. You can control this with a Conditional Tags.

  • Ben

    Great tutorial, I just wondered whether it was possible to make the slider generate the images specific (attached images) to the post/page the slider loaded on. Making it a multi-page, intuitive slider.

    Many thanks for the tutorial, great work.

    • http://www.perimetrik.de Jenso Weber

      Hi Ben!
      Did you or anybody else find out how to use the slider in different posts/sites with different images? I am trying to build a responsive portfolio website an need multiple slideshows with individual images.
      Thanks for suggestions!

  • http://confitdeisgn.com James

    I had a problem with the height of the image not re-sizing due to WP adding height and width values to the img tags.

    If anyone else has this problem you can resolve it by adding this to your css:

    img.wp-post-image {
    height: auto;
    width: auto;
    }

    Cheers for the tutorial!

    • tracersa

      Doesn’t work for me. The images are non-responsive. Any other suggestion?

  • Rob

    Great Tutorial, you guys(The whole Plus Group) are really the best …Having one issue with this one…I’ve been tweaking for like five hours and I can’t get the images to responsively resize once its being output as a wp plugin…Is it anyone else having this issue? I think it might be related to defining image sizes for wp thumbs/imgs, but I could really use some input. Thanks

  • http://www.acirdesign.com Gabriele

    I would like to ask the same question as Shane Barnes did: is there the possibility to slide posts instead of image?
    Greetings from Italy

    Gabriele

  • http://8mediaeg.com/ 8MEDIA

    amazing ,, but what could i do if i want to show more than 1 img ,, together then when you click on slid buttons it`s show another img ,.. like 3 img in one line with padding about 5 px ,, in each slid ?

  • http://www.falconsdevilafranca.cat Foix

    Hi Joseph,

    First of all, thanks for your tutorial. I’m trying to insert as a header in my webpage but I have a problem because it shows the sliders but with no images / posts. You can take a look about the behaviour in: http://www.falconsdevilafranca.cat.

    Some weeks ago, I had a similar problem with vslider plugin and I solved it changing the rights of the cache files.

    Could you please help me with this issue?

    Regards,

    Foix

    • I agree

      Yes I am running into the exact same problem!
      did you put “” in the header?

      Help us!

      thanks :)

  • DualDiesel

    How do I make a slide link through to it’s posts?

    • http://bigbigdesign.com Cynthia Closkey

      I wanted the slides to link as well, but to link to a unique URL for each slide — that is, sometimes might want to link to a page, sometimes to a post, sometimes elsewhere.

      Here’s how I did it:

      First, to allow the slide images post type to have custom fields, modified efs_register() in slide-img-type.php:

      function efs_register() {
      $args = array(
      ‘label’ => __(CPT_NAME),
      ‘singular_label’ => __(CPT_SINGLE),
      ‘public’ => true,
      ‘show_ui’ => true,
      ‘capability_type’ => ‘post’,
      ‘hierarchical’ => false,
      ‘rewrite’ => true,
      ‘supports’ => array(‘title’, ‘editor’, ‘thumbnail’, ‘custom-fields’)
      );

      Next, had to make a change to the way the Loop is being called in the slider — using query_posts() wasn’t allowing the custom fields to get set up properly. So I used get_posts() instead (which is actually the recommended way to create a secondary loop like this). Here’s the revised function:

      function efs_get_slider(){

      $slider= ‘
      ‘;

      $efs_query= “post_type=slider-image”;

      $myposts = get_posts( $efs_query );

      foreach( $myposts as $post ) : setup_postdata($post);
      $img= get_the_post_thumbnail( $post->ID, ‘full’ );
      $slide_link= get_post_meta( $post->ID, ‘link_slide_to’, true);

      $slider.=’‘ . $img . ‘‘;

      endforeach;

      $slider.= ‘
      ‘;

      return $slider;
      }

      And finally, in each slider image post, create a custom field with the key ‘link_slide_to’ that contains the full or relative URL for what you want that slide to link to. If you don’t include a ‘link_slide_to’ value for a slide, then that slide doesn’t link anywhere.

      To have each slide link to itself, use this version of the function instead:

      function efs_get_slider(){

      $slider= ‘
      ‘;

      $efs_query= “post_type=slider-image”;

      $myposts = get_posts( $efs_query );

      foreach( $myposts as $post ) : setup_postdata($post);
      $img= get_the_post_thumbnail( $post->ID, ‘full’ );
      $slide_link= the_permalink();

      $slider.=’‘ . $img . ‘‘;

      endforeach;

      $slider.= ‘
      ‘;

      return $slider;
      }

      Big thanks for this tutorial! I’ve needed a responsive slider and having this to follow saved me oodles of time.

      • JamesR

        Hi Cynthia,

        Tried to get your code working but had no joy. The Custom Fields was appearing but after I add a value and update no link appears to have been added to the slide. Could you post all of your code?

        Thanks,
        James

      • JamesR

        Should you have added:

        $slider.=’‘.$img.’‘;

        to get the link working?

        • JamesR

          Ah the comments are stripping the code out… did you have something like this in there?

          $slider.=’‘.$img.’‘;

        • JamesR

          Ah the comments are stripping the code out… did you have something like this in there?

          $slider.=’<li><a href=’.$slide_link.’>’.$img.’</a></li>’;

          • http://www.dustinschmidt.com Dustin

            Hey James, Did you ever get the comments to work in your FlexSlider?

  • http://matiasmancini.com.ar Matias Mancini

    Great tuto, but i think loading CSS and JS in the admin panel is not a good idea.
    I found a solution wrapping both wp_enqueue_xxx in a function and hooking by add_action(‘wp_enqueue_scripts’, ‘my_fn_name’)
    This hoook only load resources in the front end.

  • Chris

    Hi, Please forgive me if this is obvious, but would you elaborate on this line:

    Finally, just copy the /theme/ folder into your /envato-flex-slider/ folder. Thanks!

  • chris

    Hi,
    I am pretty sure I’ve set things up properly but am new to custom post types and don’t see where in the admin panel these settings are? Or in the post page?
    Thanks for your help.

  • pas

    Hi,
    thanks for this great tutorial..
    works well with shoortcode! how can I put it in the head with only php ?!!
    if(function_exists(‘efs_slider’)){ efs_slider(); }

    • paso

      I call the function with this?
      echo efs_get_slider();
      okay?

      • http://theodor.sinacos.com Neil

        it works, but is that safety?

    • http://robotglobaldesign Kostas

      Hey there!

  • http://www.vino-bio.com AnaGM

    Hi,
    Thanks for your great tutorial, it’s just what I was looking for!
    I tried to insert slide in my home page but I found this error:

    Notice: Undefined variable: post in public_html/wp-content/plugins/envato-flex-slider/envato-flex-slider.php on line 50

    Notice: Trying to get property of non-object in public_html//wp-content/plugins/envato-flex-slider/envato-flex-slider.php on line 50

    Could you help me, please?
    Thanks!

  • http://www.omerlevi.com Omer

    Hi, I made some changes and modifications based on your lovely tutorial here, would you mind if I publish it in the wordpress plugin repository for others to enjoy it as well?

  • http:www.gadgetspriceinindia.com Mailla

    Hi, it’s really helpful for me, please check my blog, I am using this…..thank you.

  • http://www.webtemplates-creare.com/ Paul Weston

    I am just starting out with WordPress and it is a lot to take in if I am honest. Tutorials like this though give me a confidence that I do actually know more than I thought. This tutorial will be of great use to me in the future when I really get my teeth into WordPress and give me an advantage when looking at sliders and other visual aspects.

  • Michael Hauser

    Thanks for this! It works very well.
    I noticed that the number of slides was being limited by the setting for the number of posts on the page. To fix this, I changed the query to set the number of slides explicitly:
    $efs_query= “post_type=slider-image&posts_per_page=10″;

  • Jeremyq

    Having trouble calling the function from my template page. Below is the code I’m using.

    • Jeremy

      Having trouble calling the function from my template page. I’m using…

      • http://onyudo.com martin

        jeremy,

        how did you resolves this problem? i am so far not able to my template page to call the function, either.

  • Jeremy

    Sorry about the above… didn’t keep the source in there. I got that issue sorted out though.

    Now I’m wondering how to attach a link to the image like the original does? I’ve set up a Custom Field for the link and I’d like that link to appear below where it says “Custom Field Link Here”.

    Thanks!

    $slider.=’<li><a href=”Custom Field Link Here”>’.$img.’</a><h1 class=”flex-title”>’.$ttl.’</h1><p class=”flex-caption”>’.$cpt.’</p></li>’;

    • JamesR

      Hey Jeremy,

      Don’t suppose you’d post the code you wrote to get those custom posts working?

      I’m trying to get add a link to start but having no luck with the following code:

      add_action(“admin_init”, “efs_meta_box”);

      function efs_meta_box(){
      add_meta_box(“projInfo-meta”, “Project Options”, “portfolio_meta_options”, “portfolio”, “side”, “low”);
      }

      function efs_meta_options(){
      global $post;
      if ( defined(‘DOING_AUTOSAVE’) && DOING_AUTOSAVE ) return $post_id;
      $custom = get_post_custom($post->ID);
      $link = $custom["projLink"][0];
      ?>
      Link:<input name="projLink" value="” />
      ID, “projLink”, $_POST["projLink"]);
      }
      }

      Would appreciate any help,
      James

      • JamesR

        ^*Custom Fields not Custom Posts

  • Pingback: most Popular wordpress tutorial part:1 | Write For Share

  • http://www.webinsation.com Caleb Mellas

    Hello, I followed your tutorial to create the slider and it’s not working quite right… When I used my own code the images showed up with no styling and the jQuery wasn’t working. Then I downloaded your source files and installed the plugin, and now nothing shows up? The actual images are there (I saw them using firebug) but they don’t have their css applied or the jQuery?

    I’m using the plugin on a local install of WordPress 3.2 on my LAMP server.

    Any tips?

  • http://jonyablonski.net jon

    Awesome tutorial— I’ve been a fan of Flexslider since the beginning!

    Anyways, I have a question regarding its integration with WordPress: would this plugin stay functional when a new version of WP is installed? What would be the best way to maintain the plugin?

    Thanks again,
    - j

  • Razorback

    Thanx for the tutorial, it works great, only swype doesn’t work? Controls work, but no swype. Anyone got it working?

  • fringer

    How can I remove navigation? It doesn’t scale properly, and messes up the looks.

  • Pingback: 10 Responsive WordPress Plugins to Complement Your Theme | SNS Online

  • Pingback: wp-coder.net » 10 Responsive WordPress Plugins to Complement Your Theme

  • Pingback: A Free wordpress newsletter » 10 Responsive WordPress Plugins to Complement Your Theme

  • Pingback: Responsive WordPress Plugins to Complement Your Theme

  • Pingback: SEO Enterprise-10 Responsive WordPress Plugins to Complement Your Theme

  • Daneczech

    Hi there,

    first thank’s for the tutorial. In my case, I’ve downloaded the pack and uopload in extensions…I’ve added the following code to be responsive:

    img.wp-post-image {
    height: 100%;
    width: 100%;
    }

    But when i display more than one thumb, the display one above the other, and not like a slider with the hided image…Any ideas?

    Thank’s a lot in advance!

    • Daneczech

      It seems the javascript doesn’t load…

  • Geoff Johnson

    Wow thanks for such a great tutorial. Is there a way to make this work with a single post gallery instead of creating a post type for each individual image? Thanks in advance!

  • http://www.dustinschmidt.com Dustin

    Very cool. Thanks Joe. Good work on adapting Flexslider for WordPress.

    Can anyone tell me the best way to include captions?

    Thanks!

  • Pingback: Как в WordPress создать свой слайдер с изображениями | Wordpresso

  • Pingback: 16 Useful jQuery Tutorials to Enhance your WordPress Site

  • Pingback: 16 Useful jQuery Tutorials to Enhance your WordPress Site | WPhub.biz

  • Claudio

    Thanks for the tutorial, is there any way of implementing flex slider but not as a plugin?? Tanks for any help.

  • Pingback: 16 Useful jQuery Tutorials to Enhance your WordPress Site | Wordpress Themes

  • http://www.lawrenced.co.uk lawrence

    nice tutorial, what puts me off this slider are those horrid arrow buttons

    • http://www.dustinschmidt.com Dustin

      Ok, so this is how I was able to integrate both links and captions into FlexSlider. Hope this helps anyone who has been struggling as mightily as I have. In envato-flexslider.php here is what you need for function efs_get_slider(). Just make sure you name your custom fields in your slides image_caption and image_link respectively.

      function efs_get_slider(){

      $slider= ‘<div class=”flexslider” >;
      <ul class=”slides” >’;

      $efs_query= “post_type=slider-image”;
      $myposts = get_posts($efs_query);

      foreach($myposts as $post) : setup_postdata($post);
      $img= get_the_post_thumbnail( $post->ID, ‘full’ );
      $slide_link= get_post_meta( $post->ID, ‘image_link’, true);
      $slide_caption= get_post_meta( $post->ID, ‘image_caption’, true);
      $slider.=’<li ><a href=’.$slide_link.’ >’.$img.’</a ><p class="flex-caption" >'.$slide_caption.'</p ></li >';

      endforeach;

      $slider.= '</ul >

      </div >';

      return $slider;
      }

      • Dwaynne

        How do you enable the Custom Fields on the slides screen?

    • http://www.dustinschmidt.com Dustin

      lawrence, you can disable the arrows easily in envato-flexslider.php. Just put directionNav: false and you’re all set. This is what i mean.

      function efs_script(){
      print ‘<script type=”text/javascript” charset=”utf-8″ >
      jQuery(window).load(function() {
      jQuery(\’.flexslider\’).flexslider({
      animation: “slide”,
      slideshowSpeed: 6000,
      animationDuration: 300,
      directionNav: false,
      controlNav: false
      });
      });
      </script >';
      }

      • http://bowesales.com Jesse

        How can we go about making these options accessible in the Dashboard for a user to control without having to dive into code?

  • Pingback: Talent Point Consulting

  • Pingback: 10 Responsive Slider Plugins for WordPress

  • Pingback: wp-coder.net » 10 Responsive Slider Plugins for WordPress

  • Juan

    Hi, congratulations for this GREAT tutorial, you can’t even imagine how useful was this for me.
    I have a question though that maybe someone can help me to solve. Is there any change to change this code a little bit to allow multiple sliders with different content?

    Best! and thank you very much again.

  • thibault

    Hello! Nice work here.

    I want include many sliders in my website so i want this: [ef_slider categoryname="envato" /]

    i try to modify the “query_posts” but it show all category post thumbnail.

    Someone can help me please?

    • Adam

      I’m trying the same thing now. Make sure you add this line to the shortcode function:

      $categoryname = $content

      where content will give you the content of [ef_slider]categoryname[/efslider]

      and add “&categoryname=”.$categoryname to the query line.

      I haven’t tested it yet but I don’t foresee a problem.

      • Thibault

        Thanks for responding me, i tried your solution but it seems that doesn’t work for me.

        Look at my fonction, is it right way?

        function e_get_slider(){

        $slider= ‘
        ‘;

        // assign the variable as current category

        // run the query
        query_posts(‘&categoryname=’.$categoryname);

        if (have_posts()) : while (have_posts()) : the_post();
        $img= get_the_post_thumbnail( $post->ID, ‘large’ );

        $slider.=”.$img.”;

        endwhile; endif; wp_reset_query();

        $slider.= ‘
        ‘;

        return $slider;
        }

        function e_insert_slider($atts, $content=null){

        $slider= e_get_slider();

        $categoryname = $content;

        return $slider;

        }

        add_shortcode(‘e_slider’, ‘e_insert_slider’);

        /**add template tag- for use in themes**/

        function e_slider(){

        print e_get_slider();
        }

  • Pingback: FlexSlider wordpress shortcode with category. • PHP Help Coding Programming

  • http://www.lukespoor.com Luke S

    How could I go about creating a slider manager instead and then add the slider with a shortcode of for example [slider id="55"] where the ID is to a slider you have created within the slider manager?

  • Pingback: Flexslider Wordpress – Adding Captions and External Links to Featured Images | PHP Developer Resource

  • http://www.joshuawinn.com Josh W

    This appears to be the best content slider plugin around that uses FlexSlider (my new slider of choice). It uses the most user-friendly features available, and allows content such as call-to-action button HTML to be placed in the post/slide. Why not submit a version of this to the WordPress Plugin Directory?

  • Insane_luigi

    So i know you can call it in the post page with [ef_slider], but what if i want to place the slider in one certain position on my home-page. do i call it as a plugin with

    then put the plugin in there?

    help would be Awsome!

    • http://www.webdesignerslondon.co Del

      Hello Insane_luigi,

      You should be able to wrap the slider in a div and position the div where you like using CSS.

      Hope this helps

  • infobot

    What does “Envato” have to do with “Flexislider”?

    • http://wp.envato.com/ Japh Thomson
      Staff

      Hi infobot, I’m sorry but I don’t understand your question?

      Wptuts+ is a tutorial site run by Envato, and this is a tutorial about FlexiSlider. Does that answer your question?

  • Pascal

    Hi,

    excuse me…
    but i don´t get which /theme/ folder is meant in this tutorial.
    There is no such folder in the flexslider zip folder.
    Do you mean the wordpress theme folder? Or the folder of my active theme?

    Help me please i don´t get it.

    • Pascal

      Ah forget about it.

      Found it in the Source Files on the top of the page.
      Shame on me.

      • http://wp.envato.com/ Japh Thomson
        Staff

        Hi Pascal, glad you worked it out in the end! Thanks for stopping back to update us that you’d gotten it too :)

  • http://tor.eff.org Pseudo-Responsive BS

    This is only pseudo-responsive, not professional. You need to resize and load smaller pictures for smaller devices, not only change image size – this cheap trick is bad practice and not accepted by professionals, shame on you for “teaching” this in a tutorial!

  • http://www.barkdesignchicago.com/ Shaun

    I also have captions and titles working well with this. I only quickly put it together so styles and layout are not yet set but this does work.

    First, in slider-img-type.php I added ‘excerpt’ to the supports array:

    ‘supports’ => array(‘title’, ‘editor’, ‘excerpt’, ‘thumbnail’)

    This activates the EXCERPT entry area and allows me to add a link so I can manually point the slide to a post or wherever. It is kind of ‘dumb’ though and there is no error checking.

    Then, in envato-flex-slider.php I changed to the following:

    if (have_posts()) : while (have_posts()) : the_post();
    $img= get_the_post_thumbnail( $post->ID, ‘large’ );
    $title=get_the_title($post->ID);
    $caption=get_the_content($post->ID);
    $link = get_the_excerpt($post->ID);
    $slider.=”;
    $slider .=’‘.$img.’‘;
    $slider .=”. $title .”. $caption.”;
    $slider .=”;

    endwhile; endif; wp_reset_query();

  • http://www.barkdesignchicago.com/ Shaun

    Sorry, wrong formatting for previous comment:

    if (have_posts()) : while (have_posts()) : the_post();
    $img= get_the_post_thumbnail( $post->ID, ‘large’ );
    $title=get_the_title($post->ID);
    $caption=get_the_content($post->ID);
    $link = get_the_excerpt($post->ID);
    $slider.=”;
    $slider .=’‘.$img.’‘;
    $slider .=”. $title .”. $caption.”;
    $slider .=”;

    endwhile; endif; wp_reset_query();

  • http://onyudo.com martin

    this is great! however, i’m having one problem i can’t figure out:

    my slides custom post types do not show the typical Featured Image box on the admin end.

    i’ve poured over this tutorial several times now and can’t figure it out.

    i’m using a local install of WP 3.4, if that makes any difference.

    cheers!

    • http://onyudo.com martin

      nevermind! one little typo on my part was all it was!

      cheers!

  • Pingback: My Stream | Skeleton to WordPress: Finishing Off | My Stream

  • Pingback: Skeleton to WordPress: Finishing Off | How to Web

  • http://bowesales.com Jesse

    So far this tutorial has been a great start to implementing Flex Slider into a WordPress theme but clearly we need more than this. Can we update this tutorial Tuts+?

    Let’s get the captions and links added, let’s take a stab at including an options page to control the transitions and speeds or even switch up the themes, and how about including multiple slide shows on a single page or throughout the site using different images via a category or post ID? Heck, even including a hover state for the direction nav’s could be cool.

    We can’t keep hacking away at this and posting our pseudo results in the comments here for others to experiment with.

    This is such a great tutorial, but let’s step it up a bit!

  • abi

    Is there anyway that flexslider will be a header slider? Thanks

  • http://www.ericelliot.com Eric

    Hey All,

    I was having quite a bit of trouble getting the images to link to specific URLs and including captions, none of the above solutions seemed to be working for me. So I thought I would share my solution, hopefully it helps someone else…

    Inside of envato-flex-slider.php, I used the following code:

    function efs_get_slider(){

    $slider= ‘
    ‘;

    $efs_query= “post_type=slider-image”;
    query_posts($efs_query);

    if (have_posts()) : while (have_posts()) : the_post();
    $img= get_the_post_thumbnail( $post->ID, ‘full’ );
    $slide_link= get_the_content( $post->ID );
    $caption = get_the_excerpt();

    $slider.=’‘.$img.”.$caption.’‘;

    endwhile; endif; wp_reset_query();

    $slider.= ‘
    ‘;

    return $slider;
    }

    ** So with using that code, my slide posts have the link url entered in the content box, and the text for captions are entered in the excerpt box.

    • http://www.ericelliot.com Eric

      Sorry, some of that code didn’t copy correctly, here it is again:

      function efs_get_slider(){

      $slider= ‘<div class=”flexslider”>
      <ul class=”slides”>’;

      $efs_query= “post_type=slider-image”;
      query_posts($efs_query);

      if (have_posts()) : while (have_posts()) : the_post();
      $img= get_the_post_thumbnail( $post->ID, ‘full’ );
      $slide_link= get_the_content( $post->ID );
      $caption = get_the_excerpt();

      $slider.=’<li><a href=’.$slide_link.’>’.$img.’<p class=”flex-caption”>’.$caption.’</p></a></li>’;

      endwhile; endif; wp_reset_query();

      $slider.= ‘</ul>
      </div>’;

      return $slider;
      }

      • http://www.mainstreetwebworx.com Jeremiah

        This seems to totally break the plugin on my end? Anyone else moved any further? Would love to have this support HTML content!

  • tobi

    hi,

    in debug mode with WP 3.4 i get a notice when activating the plugin:

    “… slider wp_enqueue_script was called incorrectly. Scripts and styles should not be registered or enqueued until the wp_enqueue_scripts, admin_enqueue_scripts, or init hooks….”

    but i also find a solution…so in case you wanna get rid of that notice do the following:

    replace:

    /*Add the Javascript/CSS Files!*/
    wp_enqueue_script(‘flexslider’, EFS_PATH.’jquery.flexslider-min.js’, array(‘jquery’));
    wp_enqueue_style(‘flexslider_css’, EFS_PATH.’flexslider.css’);

    with:

    add_action(‘wp_enqueue_scripts’, ‘my_scripts_method’);
    function my_scripts_method() {
    wp_enqueue_script(‘flexslider’, EFS_PATH.’jquery.flexslider-min.js’, array(‘jquery’));
    wp_enqueue_style(‘flexslider_css’, EFS_PATH.’flexslider.css’);
    }

  • Ricardo

    Is there a way of doing all that, but with the option to implement that in the theme and not using as a plugin?

  • Jeff

    Great tutorial except i am having issues getting it working. I created the plugin and everything just fine, but when i view the page after adding images, nothing shows up. the UL and LI are made but all LI are set to display:none. You can view the issue here: http://urbanfoxmedia.ca/testbed/IslandCarCredit/?page_id=32

    I realized that your tutorial code for adding the custom post type was missing the ? infront of the opening php tag. which oddly enough without the ? it puts an error at the top of my page but the slider displays properly, as soon as i re add the ? to the code below the slider stops working, as you can see on my test site.

    Any help would be appreciated.

  • Pingback: Top 10 Wordpress Plugins 2012 Damselfly Development

  • Ben Adam

    Is there a way to support videos with this slider?

  • Pingback: φ(・∀・)メモメモ:Create a Responsive Slider Plugin With FlexSlider for WordPress | Wptuts+

  • Pingback: w3talks 10 адаптивных слайдеров для WordPress » w3talks

  • Pingback: Skeleton to WordPress: Finishing Off | Webdesigntuts+

  • http://www.facebook.com/jonathanbeech3 Jonathan Beech

    Hi

    I am using the slide show in the Skeleton to WordPress tutorial over at Nettuts. However, when wordpress debug is set to true I get the following error.

    Undefined variable: post in /home/sites/jonathanbeech.co.uk/public_html/sandpit/wp-content/plugins/envato-flex-slider/envato-flex-slider.php on line 55 Notice: Trying to get property of non-object in /home/sites/jonathanbeech.co.uk/public_html/sandpit/wp-content/plugins/envato-flex-slider/envato-flex-slider.php on line 55

    The code is here if (have_posts()) : while (have_posts()) : the_post();

    $img= get_the_post_thumbnail( $post->ID, 'large' );

    $slider.=''.$img.'';

    endwhile; endif; wp_reset_query();

    Not a showstopper but if anyone can demonstrate some understanding and let me know what can be done to kill this error then that would be helpful

  • Pingback: 6 Free Responsive WordPress Slider Plugins You Can Use On Your Blog | Web Tech News | Tech News | Mobile Phone News

  • Pingback: Courtyard Creative | HOW I REDESIGNED THE COURTYARD CREATIVE WEBSITE

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