Easy-to-follow video tutorials help you learn software, creative, and business skills.Become a member

Using FlexSlider to create a responsive slider

From: WordPress: Building Responsive Themes

Video: Using FlexSlider to create a responsive slider

Featured content sliders are a great way of showcasing specific content on a site. That said, they can also be a great hindrance when trying to create a responsive site. There are ways around this problem, but they usually involve a lot of code wrangling and quite a bit of JavaScript and CSS sorcery. Fortunately, much of this has already been solved by others, and in a solution called FlexSlider, you will find a featured content slider that is both responsive, functional, and even includes swipe behaviors for smartphones and tablets and lots of other advanced features.

Using FlexSlider to create a responsive slider

Featured content sliders are a great way of showcasing specific content on a site. That said, they can also be a great hindrance when trying to create a responsive site. There are ways around this problem, but they usually involve a lot of code wrangling and quite a bit of JavaScript and CSS sorcery. Fortunately, much of this has already been solved by others, and in a solution called FlexSlider, you will find a featured content slider that is both responsive, functional, and even includes swipe behaviors for smartphones and tablets and lots of other advanced features.

Let's take a look at how you can include FlexSlider into the Anaximander theme, or any other theme for that matter. The first thing we need to do is get FlexSlider itself, and we get it here at woothemes.com/flexslider. This, by the way, is also where you'll find all the documentation and examples and other information. And the amount of stuff you can do here is quite extensive, so it's worth taking a close look at the site. So, I am going to download FlexSlider here, and get it onto my computer, and then I'll open this folder.

And from here, I only need three components. I want flexslider-min. This is the JavaScript library. I want the flexslider.css CSS file, and I want the images folder. I'll open my theme next to it, and I am going to put the flexslider.css file, along with the images folder, into the CSS folder. Now that I have the files I need, I need to tell WordPress to use FlexSlider, and I am going to use the same enqueue method I used for FitVids earlier.

So, we'll go to functions.php, scroll all the way to the bottom, make some space, and here I want to add the functions to call FlexSlider in. Just like before, this requires quite a bit of code, so I've compiled it all for you, and you just have to copy it and paste it in. So you see here under 10.01, you'll find the FlexSlider code. Just go down and copy all of it and paste it in to functions.php. If we take a quick look at this function, it's exactly the same type of function that we saw previously with FitVids.

We have the function itself, aximander_flexslider. It's called down here add_action. On initiation, we call anaximander_flexslider. And here we do that register_script function again, where we give the script a name, we call it from the template_directory, and it's called then jquery.flexslider_minified. We enqueue that script, and then we also enqueue the style sheet. So we go wp_register_style, give the style a name, point to the style, template_directory css/flexslider.css, and then we enqueue the style here.

Finally, we have to add the script function, and this is where, if you want to customize FlexSlider further, you would add your extra script, because if you go into the examples of what is possible with FlexSlider, you'll see there's tons of extra functionality you can hook into if you want to and you can make lot of customizations with this tool. If you do that, this is where you would place it. But for now, we're just going to save it and then we have to add some content to our page that can be inside the FlexSlider.

To do that, I am going to go and modify index.php. That's the template file that controls the front page. So, I'll go back to my theme, find index.php, edit it with Notepad, and then directly under div content main here, I am going to add some new lines, and then here I'm going to paste in some dummy content. Back in my code_snippets file, I've already created that dummy content for you. So, you can just copy out from the beginning comment till the end comment here and paste it in, and you'll see all we're doing here is creating a divider with the class FlexSlider that has an unordered list with a class slides, and each of the list items within this unordered list will be one of the slides.

You can also see that each of the list item has an image and then a caption. When I save this and reload my page in my browser, you see FlexSlider appears at the top. And right now, FlexSlider is pulling images directly from my Flickr account. And we can even navigate between the images using either of these navigation buttons or by using the buttons down here on the bottom. But the coolest thing is, as I said before, FlexSlider, as the name suggests, is responsive and flexible, which means simply by adding FlexSlider into the site, like we just did, you automatically have a fully responsive slider.

Before we go any further, I want to say two things. First of all, you should go check out the live demo of FlexSlider, because you'll see that you have a lot of different options when it comes to how you want to use FlexSlider. You have the standard version, which is what we just included, and you can also add things like thumbnail navigation or even add a carousel that cycles through multiple pieces of content. All the documentation for these types of behaviors, along with code examples like the one you see right here, can be found on the FlexSlider web site.

And there is one more thing I want to point out. FlexSlider is a perfect example of an open source application in constant development. That means there are always developers working on improving FlexSlider, so chances are, if you implement it, it may not work exactly the same way that I'm showing you. But that also means it probably has even more features and is even more advanced. So, if you want to use FlexSlider, be sure to go to the web site, download the latest version, read the documentation, and make sure you're using it to its fullest.

Show transcript

This video is part of

Image for WordPress: Building Responsive Themes
WordPress: Building Responsive Themes

39 video lessons · 17831 viewers

Morten Rand-Hendriksen
Author

 
Expand all | Collapse all
  1. 4m 5s
    1. Welcome
      1m 4s
    2. Using the exercise files
      1m 27s
    3. What you should know before watching this course
      1m 34s
  2. 8m 36s
    1. What is responsive design?
      4m 16s
    2. The different faces of WordPress on mobile
      1m 55s
    3. Exploring the finished Anaximander theme
      2m 25s
  3. 9m 38s
    1. Getting and installing the Anaximander theme
      1m 53s
    2. Configuring basic theme options
      7m 45s
  4. 23m 51s
    1. Deciding what screen sizes to design for
      4m 11s
    2. Thinking responsively: Designing for many different screen sizes
      6m 23s
    3. Visualizing content realignment for better markup
      4m 35s
    4. Designing menus
      4m 52s
    5. Adding responsive images and videos
      3m 50s
  5. 26m 8s
    1. What are media queries and how do they work?
      4m 18s
    2. Exploring CSS3, progressive enhancement, and graceful degradation
      3m 27s
    3. Understanding best practices for media queries
      3m 57s
    4. Creating a responsive frame
      5m 12s
    5. Customizing media queries with the Chrome Developer Tools
      5m 28s
    6. Taking device width into account
      3m 46s
  6. 11m 1s
    1. Resizing the site title and the description
      8m 22s
    2. Adding media queries to the header
      2m 39s
  7. 11m 22s
    1. Making the menu responsive
      3m 35s
    2. Creating a different menu design for small screens
      7m 47s
  8. 19m 22s
    1. Making a responsive single-post layout
      6m 11s
    2. Making images responsive
      4m 37s
    3. Making videos responsive by including FitVids
      8m 34s
  9. 7m 45s
    1. Making the sidebar responsive
      5m 10s
    2. Hiding sidebars on mobile
      2m 35s
  10. 7m 28s
    1. Dealing with footer widgets
      5m 11s
    2. Adding navigation links that return to the top of the page
      2m 17s
  11. 12m 54s
    1. Using FlexSlider to create a responsive slider
      6m 2s
    2. Creating a loop to show sticky posts in a featured slider
      6m 52s
  12. 24m 37s
    1. What is jQuery Masonry?
      3m 41s
    2. Installing jQuery Masonry
      4m 45s
    3. Configuring the index page with Masonry
      7m 0s
    4. Using CSS to finalize the Masonry layout
      6m 17s
    5. Adding media queries to the Masonry index
      2m 54s
  13. 9m 11s
    1. Exploring hidden features of the Anaximander theme
      5m 51s
    2. Where to go from here
      3m 20s

Start learning today

Get unlimited access to all courses for just $25/month.

Become a member
Sometimes @lynda teaches me how to use a program and sometimes Lynda.com changes my life forever. @JosefShutter
@lynda lynda.com is an absolute life saver when it comes to learning todays software. Definitely recommend it! #higherlearning @Michael_Caraway
@lynda The best thing online! Your database of courses is great! To the mark and very helpful. Thanks! @ru22more
Got to create something yesterday I never thought I could do. #thanks @lynda @Ngventurella
I really do love @lynda as a learning platform. Never stop learning and developing, it’s probably our greatest gift as a species! @soundslikedavid
@lynda just subscribed to lynda.com all I can say its brilliant join now trust me @ButchSamurai
@lynda is an awesome resource. The membership is priceless if you take advantage of it. @diabetic_techie
One of the best decision I made this year. Buy a 1yr subscription to @lynda @cybercaptive
guys lynda.com (@lynda) is the best. So far I’ve learned Java, principles of OO programming, and now learning about MS project @lucasmitchell
Signed back up to @lynda dot com. I’ve missed it!! Proper geeking out right now! #timetolearn #geek @JayGodbold
Share a link to this course

What are exercise files?

Exercise files are the same files the author uses in the course. Save time by downloading the author's files instead of setting up your own files, and learn by following along with the instructor.

Can I take this course without the exercise files?

Yes! If you decide you would like the exercise files later, you can upgrade to a premium account any time.

Become a member Download sample files See plans and pricing

Please wait... please wait ...
Upgrade to get access to exercise files.

Exercise files video

How to use exercise files.

Learn by watching, listening, and doing, Exercise files are the same files the author uses in the course, so you can download them and follow along Premium memberships include access to all exercise files in the library.


Exercise files

Exercise files video

How to use exercise files.

For additional information on downloading and using exercise files, watch our instructional video or read the instructions in the FAQ .

This course includes free exercise files, so you can practice while you watch the course. To access all the exercise files in our library, become a Premium Member.

Are you sure you want to mark all the videos in this course as unwatched?

This will not affect your course history, your reports, or your certificates of completion for this course.


Mark all as unwatched Cancel

Congratulations

You have completed WordPress: Building Responsive Themes.

Return to your organization's learning portal to continue training, or close this page.


OK
Become a member to add this course to a playlist

Join today and get unlimited access to the entire library of video courses—and create as many playlists as you like.

Get started

Already a member ?

Become a member to like this course.

Join today and get unlimited access to the entire library of video courses.

Get started

Already a member?

Exercise files

Learn by watching, listening, and doing! Exercise files are the same files the author uses in the course, so you can download them and follow along. Exercise files are available with all Premium memberships. Learn more

Get started

Already a Premium member?

Exercise files video

How to use exercise files.

Ask a question

Thanks for contacting us.
You’ll hear from our Customer Service team within 24 hours.

Please enter the text shown below:

The classic layout automatically defaults to the latest Flash Player.

To choose a different player, hold the cursor over your name at the top right of any lynda.com page and choose Site preferences from the dropdown menu.

Continue to classic layout Stay on new layout
Exercise files

Access exercise files from a button right under the course name.

Mark videos as unwatched

Remove icons showing you already watched videos if you want to start over.

Control your viewing experience

Make the video wide, narrow, full-screen, or pop the player out of the page into its own window.

Interactive transcripts

Click on text in the transcript to jump to that spot in the video. As the video plays, the relevant spot in the transcript will be highlighted.

Learn more, save more. Upgrade today!

Get our Annual Premium Membership at our best savings yet.

Upgrade to our Annual Premium Membership today and get even more value from your lynda.com subscription:

“In a way, I feel like you are rooting for me. Like you are really invested in my experience, and want me to get as much out of these courses as possible this is the best place to start on your journey to learning new material.”— Nadine H.

Thanks for signing up.

We’ll send you a confirmation email shortly.


Sign up and receive emails about lynda.com and our online training library:

Here’s our privacy policy with more details about how we handle your information.

Keep up with news, tips, and latest courses with emails from lynda.com.

Sign up and receive emails about lynda.com and our online training library:

Here’s our privacy policy with more details about how we handle your information.

   
submit Lightbox submit clicked
Terms and conditions of use

We've updated our terms and conditions (now called terms of service).Go
Review and accept our updated terms of service.