So I’m learning WP and I want to create a rotating image slider for the header (like in this) using Theme Customization API. But I can’t figure out how to and what setting should I use to take the images and store it for later animation in HTML/JS. Help?
Leave a Reply
You must be logged in to post a comment.
We can do that! First, you’ll need to add a custom section on the Theme Customizer, containing all the image uploads (we’ll use 3 for this example):
Using that code will add a new section, containing 3 file uploads. For now, we’re just using images. Later, you can go back and add descriptions, target URLs, etc. Once you’ve uploaded three slides, all you need to do is call them in your templates.
Calling a theme option is pretty dang easy, using the function get_theme_mod(). To call the first slide, for instance, you just need to use:
echo get_theme_mod('first_slide')
So if you wanted to place a slider on your homepage, for instance, you might open index.php and add some markup like this:
Of course, you’ll still need a healthy dose of CSS and JS to make the actual slider, but that’s the basics of uploading, storing, and calling images with the Theme Customizer.
If you’re still a bit hazy, Otto has written a perfect introduction on the rest of the functionality: http://ottopress.com/2012/how-to-leverage-the-theme-customizer-in-your-own-themes/