How to Integrate Nivo Slider into WordPress

Published On November 18, 2010
74 Comments Leave a Comment

Integrate Nivo Slider with WordPress

I am sure many of you have already heard or read about the sleek NIVO Image Slider built using jQuery and HTML. If you haven’t, you can go to the website and check it out for yourself. The slider allows you to display images and HTML text via 9 unique transition effects.

This slider serves as a static slider using only CSS/HTML and jQuery. Today, I am going to show you how you can integrate this nifty looking slider component into your WordPress theme effectively (a much easier way than what you have already known). Read on!

1. First Steps First

Download the NIVO slider files to your desktop and extract them to a folder. Copy the files called arrows.png, bullets.png and loading.gif from the nivo-slider/demo/images folder and paste them into your WordPress Theme /Images folder.

Now in your WordPress theme, decide an appropriate place where you want the slider to show up. For this particular example, I will be using the WordPress theme – “Twenty Ten (2010)” that comes with a default installation of WordPress (3.0+).

I want my slider to show up on the main page, so I will open up the index.php file for editing.

2. A Custom LOOP for the Slider Posts

To bring WordPress content into the slider, we will be defining a custom query loop into the index.php file. This loop will pull up posts from a particular category and display them into the slider. To do this, in the index.php file, after the following line :-

[html] <div id="content" role="main">
[/html]

Paste the following piece of code :-

[php] <div id="slider">
<?php $my_query = new WP_Query(‘showposts=5&category_name=featured’); while ($my_query->have_posts()) : $my_query->the_post(); ?>
<a href="<?php the_permalink() ?>" title="<?php the_title(); ?>">
<img src="<?php echo get_post_meta($post->ID, ‘nivoimage’, true); ?>" alt="" title="<?php the_title(); ?>" />
</a>
<?php endwhile; ?>
</div>
<br clear="all" />
[/php]

The above code will pull 5 posts (showposts=5) from the category called “featured” (category_name=featured) from your WordPress blog. So make sure that you have a category by that name or change the name accordingly in the above code.

For the images to show up, you will have to use custom fields. To do that, while creating the post/s in the aforementioned category, just upload an image and copy its upload path. After that, create a new custom field called “nivoimage” (without quotes) and paste the copied path of the image into its value. Read more about the Usage of Custom Fields if you are not so sure about them.

3. The jQuery Magic

Now open up the extracted NIVO slider folder on your desktop, copy the file called jquery.nivo.slider.pack.js and paste it into your WordPress theme folder. After doing this, open up the footer.php file of your theme and just above the ending </body> tag, paste the following lines :-

[html] <script src="http://ajax.googleapis.com/ajax/libs/jquery/1.4.2/jquery.min.js" type="text/javascript"></script>
<script src="<?php bloginfo(‘template_directory’); ?>/jquery.nivo.slider.js" type="text/javascript"></script>
<script type="text/javascript">
$(window).load(function() {
$(‘#slider’).nivoSlider();
});
</script>
[/html]

The above code will include the jQuery library and the NIVO script that you had put in your theme folder to your applied WordPress theme.

4. The CSS

The last step is to include the NIVO slider’s CSS code into your theme stylesheet. So, open up the file called style.css from your theme folder and paste the following code at the end of file :-

[css] /* The Nivo Slider styles */
.nivoSlider {position:relative;}
.nivoSlider img {position:absolute;top:0px;left:0px;}
.nivoSlider a.nivo-imageLink {position:absolute;top:0px;left:0px;width:100%;height:100%;border:0;padding:0;margin:0;z-index:60;display:none;}
.nivo-slice {display:block;position:absolute;z-index:50;height:100%;}
.nivo-caption {position:absolute;left:0px;bottom:0px;background:#000;color:#fff;opacity:0.8;/* Overridden by captionOpacity setting */
width:100%;z-index:89;}
.nivo-caption p {padding:5px;margin:0;}
.nivo-caption a {display:inline !important;}
.nivo-html-caption {display:none;}
.nivo-directionNav a {position:absolute;top:45%;z-index:99;cursor:pointer;}
.nivo-prevNav {left:0px;}
.nivo-nextNav {right:0px;}
.nivo-controlNav a {position:relative;z-index:99;cursor:pointer;}
.nivo-controlNav a.active {font-weight:bold;}
/*============================*/
/*=== Custom Slider Styles ===*/
/*============================*/
#slider {position:relative;width:618px;height:246px;background:url(images/loading.gif) no-repeat 50% 50%;}
#slider img {position:absolute;top:0px;left:0px;display:none;}
#slider a {border:0;display:block;}
.nivo-controlNav {position:absolute;left:260px;bottom:-42px;}
.nivo-controlNav a {display:block;width:22px;height:22px;background:url(images/bullets.png) no-repeat;text-indent:-9999px;border:0;margin-right:3px;float:left;}
.nivo-controlNav a.active {background-position:0 -22px;}
.nivo-directionNav a {display:block;width:30px;height:30px;background:url(images/arrows.png) no-repeat;text-indent:-9999px;border:0;}
a.nivo-nextNav {background-position:-30px 0;right:15px;}
a.nivo-prevNav {left:15px;}
.nivo-caption {text-shadow:none;font-family: Helvetica, Arial, sans-serif;font-size:14px;}
.nivo-caption a {color:#efe9d1;text-decoration:underline;}
[/css]

Concluding Instructions

If you have followed the above steps carefully, your NIVO slider should start working flawlessly. Some points to note if things aren’t working the way they should :-

  • Make sure you have a category by the name “featured” or anything else if you changed the code in the custom loop (Step 2)
  • Check that you have only one Unique Identifier called #slider in your CSS file. Also see to it that none of the CSS classes overlap with any of your existing styles.
  • When uploading images to your posts, make sure that they are of same dimensions so that there is no inconsistency during transitions (or, if you are experienced enough, try and integrate some automatic image resizer script into this on your own)

If you liked this tutorial, please don’t forget to leave a comment. I will appreciate that!

74 replies on “How to Integrate Nivo Slider into WordPress”

Joshua A. Price Reply

I have been just reading through your site it is very well crafted, I am looking around on the net searching for the best way to start this blog thing and your website happens to be extremely professional.

web development resources Reply

Thank you very much. I am creating a wordpress theme for my client. I will add this nivo slider into the theme.

peccary Reply

Hello, I have browsed most of your posts. This post is probably where I got the most useful information for my research. Thanks for posting, maybe we can see more on this. Are you aware of any other websites on this subject.

osama shk Reply

Thank you for some other informative website. The place else may just I get that kind of information written in such a perfect method? I have a venture that I am simply now running on, and I’ve been at the glance out for such info.

The Great American Fruit Tree Campaign Reply

I’m a bit new to web design, so I’m a little slow on the pickup. I am looking for a nicer slider than the one that I have, but one that will pick up the latest post from each of my 6 categories. Does this one do that?

proxy Reply

“Magnificent goods from you, man. I have understand your stuff previous to and you are just extremely excellent. I actually like what you have acquired here, certainly like what you’re saying and the way in which you say it. You make it entertaining and you still care for to keep it sensible. I cant wait to read far more from you. This is really a tremendous web site.”

futera? do gitary basowej Reply

“Wow, amazing blog layout! How long have you been blogging for? you make blogging look easy. The overall look of your website is excellent, as well as the content!. Thanks For Your article about Quen Somos ? | grupo de consumo responsable .”

Squishface Reply

This broke my site. The code doesn’t work if you follow the instructions. It prevents the page from loading.

I would consider this code malicious until it is fixed.

jgbNeatDesign Reply

Hello There ! I really like your tutorial. It is nice and easy to read and understand. I just went to read a similar on another site. almost the same magic. I appreciate your help. Really thank you !

eric Reply

Thank for this tut. This might help me in building my own theme with custom post type and using nivo to display featured items. Anyone who have successfully integrate the nivo slider please share your site. ty

Tim Reply

Hi Jai!

Thanks for posting the tutorial. This really helped me a lot understand how to incorporate a JQuery slider into my site. However, I did run into a problem. I followed the tutorial down to every detail but my image content is not showing up – only the loading icon. I haven’t been exposed to Custom Fields before reading through this tutorial – did a ton of research about them but can’t seem to understand how to use them properly in this tutorial. I think this is the only problem I am having from getting it to work. I tried doing 1 post with 3 custom fields, and also 3 different posts each with its own unique custom field – both don’t appear to work. I used category ‘featured’ for the post and custom field name ‘nivoimage’ as well.

If you could do a walk through of that step, I would really appreciate it!

Luis Angel Reply

Stef, I have the same problem. Review the code because when I paste it the ‘ character was ´.It would be ‘template_directory’ and no ´template_directory´. It also occurs in the script code.

Gopal Aggarwal Reply

Thanks a lot! Have been trying to integrate a slider into WordPress. Though it is not yet complete, but with your tutorial (especially putting the code in footer), I’ve made some progress.

Will do some attempts and get it to work.

Thanks again.

Warm regards
Gopal

Allen Reply

you are great, thanks for sharing this to all of us, but i use jsp, do you have the tutorial applied in jsp web page? that would be more appreciated.

Adhitya Fernando Reply

great post, jai.
How to use nivo slider in a page?
I want to display an image slider on my page.
I’m using empire elegant themes 1.3 on my web, Shortcode to insert nivo slider image already included in that theme. i have tried to insert the code and choose the category for the image. The image succesfully displayed, but just single image without slider. The slider won’t wor
Please help me jai.
I’m stuck with this problem.
Thanks for your kindness.

Yogesh Reply

Hi really great tutorial. I am currently working on a website based on a WordPress theme. Theme has a built in Nivo slider feature. Posts are displayed as slides. But in my design i want to change the bullets design below the slider. I wanted some text related to a slider image instead of bullet for that image. So that when user click on that text then the image related to that slide should be shown. Basically list of text instead of bullets below the slider. Your help will be greatly appreciated.

Brandon Reply

Great tutorial. Just wanted to give people an easier way to retrieve the post featured image without adding custom fields.

Use:
<img src="ID) ); ?>

Instead of:
<img src="ID, ‘nivoimage’, true); ?>

Brandon Reply

Oops. Let me try removing some tags to get this to display properly. Don’t forget to add the quotes and proper tags back to get this working correctly.

Use:
img src=?php echo wp_get_attachment_url( get_post_thumbnail_id($post->ID) ); ?>

Instead of:
ID, ‘nivoimage’, true); ?>

vaibhav Reply

Nivo slider is working well. al the effects and image location is perfect,,
but bullets and arrows are not showing there
even i place border to navigation and prev and next navigation.
thees fields are there, but bullets and arrows images not displaying.
please help me

camikat Reply

I use worpress with twentyeleven theme and when I look my blog on smartphone (iPhone), I can’t see the entire nivo image slider.

I would like to adjust the image in width 100% to see the entire image on my smarphone.
Coudd somebody please give some help to set JS or other files ?

Thanks to help

Sarah Reply

Im using your tutorial but in /jquery.nivo.slider.js is currently injected by attacker. Could you tell me how could resolve the problem. Now, I just re-upload /jquery.nivo.slider.js with the one

Sunil Sharma Reply

Hi Jai,

Your tutorial is awesome. I tried to do it successfully on my blog. But I have one question that can I change bullets (showing under slider) with menu items like newscast theme (available in themeforest) does perfectly. If it is possible please guide how I can connect it to my website’s menu items.

Regards n thanks

Sunil

Sunil Sharma Reply

Sorry to comment again. but I forgot to mention that I tried nivo slider in elemin theme (by themify) and wordpress default 2011 theme. I don’t know if it is possible to add one theme’s functionality in another theme like news cast. Is there any method to add such functionality in 2011, kindly also write an article on how we can do.

Thanks,

Sunil

Drizzy Reply

I’ve using your tutorial above and work. but the images slide was drop down, how to solve this error. (I’m changing image size to 460 – 220 from the default 618 – 246), thanks

Braid Hair Extensions Reply

Useful information, was just looking something similar for the company blog to give it a fresh look. Let’s see how best we can implement this.
Emily

Christopher Neetz Reply

Hi, love your post. I have one issue though. No matter what category I select, there is always an extra slide that holds nothing. Do you know what this could be from?

werbefotograf Reply

This tutorial is a great postc. My new Website – 4 days old – with the nivo slider looks fantastic. THANK YOU JAI. Take care and regards from cologne

David Gómez Reply

I can’t make ir work, i already double check the code and everything is fine, im also using the Twenty Ten theme.

I tried the wp-nivo-slider plugin and is working ok, but the CSS from that plugin sucks and makes the script look really ugly.

My problem is the slider doesn’t appear, the code is generated at the right position but the slider never shows, can you help me?

Eugene Gordin Reply

Thank you so much for this tutorial – it is quite helpful.

I cannot seem to find a way to have Nivo load the content of the post using the nivo-html-caption class (since the content has HTML).

The instructions to Nivo explain how to have html in the captions, but require that the div with the html be outside the slider div. This doesn’t work for wordpress however because the loop needs to be inside the slider div.

Any suggestions?

Ajinkya Reply

Thanks for super cool slider n tut. I have embeded it in my homepage of my website (click on my name above), but problem is IMAGES are not showing up on sldier.. only text is coming & image space is coming as a box. Please advise 🙂

daniel Reply

aah, got it working… path in the given script wasn’t correct. Can I also put some images in the code? just like the nivo slider demo?

Erwin Reply

Agree with Keenan. With a few modifications you can easily use the Featured Image feature so you don’t have to muck around with custom fields. Still a great tut!!

fever18 Reply

Is there any easy way to use this Nivo slider.
I dont want to play with the coding of my wordpress files..
Please help me with some plugin to use this functionality.

Lukman Reply

Very useful tutorial Jai.

But please check this out:

..copy the file called jquery.nivo.slider.pack.js and paste it into your WordPress theme folder.

<script src="/jquery.nivo.slider.js” type=”text/javascript”>

$(window).load(function() {
$(‘#slider’).nivoSlider();
});

see the script path?

Jai Reply

What’s wrong with the path?? I don’t see an issue. It is /jquery.nivo.slider.js and that’s what is there in the tutorial

Lukman Reply

Yes, but here is what you say:

Now open up the extracted NIVO slider folder on your desktop, copy the file called jquery.nivo.slider.pack.js and paste it into your WordPress theme folder

Keenan Payne Reply

Great tutorial Jai, but wouldn’t there be an easier way to implement Nivoslider into themes using the post thumbnails introduced in WordPress 3.0?

Jai Reply

Yes. I have knowledge of the plugin. This tutorial is for bloggers and developers who want to integrate the slider into the template without the use of an extra plugin. 🙂

Leave a Reply to Allen Cancel reply

Your email address will not be published. Required fields are marked *