Nov
18

How to Integrate Nivo Slider into WordPress

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!

This post was viewed 47,129 times

82 Comments to “How to Integrate Nivo Slider into WordPress” | Leave a Comment!

  1. shannon says:

    very, very neat!!! great function

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

  3. Thanks to my father who told me about this webpage, this webpage is
    genuinely remarkable.

  4. Telecharger says:

    i want to do it through a plugin from the admin

  5. Nice site i like it, check this one for getting hosgator discount coupon codes.

  6. 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?

  7. proxy says:

    “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.”

  8. proxy says:

    “Im incompetent at view this web site properly on opera I am there is a problem”

  9. “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 .”

  10. Squishface says:

    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.

  11. henk says:

    Your code is bad and you should feel bad.

    Use another tut rather, this one throws up an unexpected error on step 1. Fuck doing tutorials where you first have to clean up their code.

  12. ali says:

    fuck your codes

  13. neosplash says:

    Parse error: syntax error, unexpected ‘=’ in line 3 of the code placed in index.php. Using Twenty Twelve theme. Any help?

  14. 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 ! visit my website at http://tikwenpam.com , I’m using the graphene theme as a framework and it has a native slider that work really good. See yOu !

  15. Hello There ! I really 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 ! visit my website at http://tikwenpam.com , I’m using the graphene theme as a framework and it has a native slider that work really good. See yOu !

  16. melvin says:

    Thanks a lot for this tutorial, I am wordpress newbie trying to create my own theme. this was easy helpful

    thanks

  17. eric says:

    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

  18. Tony says:

    The php will crash the page. Fix it by replacing the open and close quotes with single quotes around | showposts=5&category_name=featured | and | nivoimage like this ‘nivoimage’

  19. Abhishek says:

    Thanks for the tut. Though I am a bit reluctant to edit the files myself. Is there any plugin available for it?

  20. muzammil says:

    Its working but how could we control the speed and number images in this slider

  21. Phil says:

    Meant to say

    On 3.4.1 when opening up the index.php it gets lost from there. ie
    div id=”content” role=”main” isn’t there.

  22. Phil says:

    On 3.4.1 when opening up the index.php it gets lost from there. ie
    isn’t there.

  23. Amin says:

    thank you! helped a lot!
    Regards!

  24. Ahmed says:

    Sir, how to show 5 random posts instead of category “featured”? :)

  25. graham says:

    cheers for tute m8 a much needed insight into installing the nivo slider as been struggling a little bit to place it on my web design. its working now :).thanks

  26. Tim says:

    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!

  27. Stef says:

    Am I the only one that gets an error when adding the PHP? I mean I see no one else complaining. Is it just me?

    • Luis Angel says:

      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.

  28. Nivo slider is not so good slider for me :(

  29. 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

  30. Allen says:

    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.

  31. Wouldn’t it be easier to grab the featured image of the post and stick it in there?

  32. s says:

    i want to do it through a plugin from the admin

  33. Load Pull says:

    This is such an important topic, thank you so much for sharing.

  34. britain says:

    Hello,
    with this tutorial, we can add the slider with thumbnails on the demo as 4? Thank you
    http://nivo.dev7studios.com/demos/4/
    thank you

  35. 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, http://www.adhityafernando.com. 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.

  36. Yogesh says:

    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.

  37. Brandon says:

    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 says:

      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); ?>

  38. vaibhav says:

    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

  39. camikat says:

    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

  40. Sarah says:

    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

  41. Sunil Sharma says:

    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 says:

      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

  42. Alfredo says:

    Hi Jai, love your tutorial!
    Is it possible some tweak to do the same thing with pages?

  43. Drizzy says:

    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

  44. 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

  45. alimas says:

    well the jquery magic worked for me and you have compiled some of great work han keep it cool and nice

  46. 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?

  47. Thank you so much for this tutorial…

  48. Thanks for this. I was wondering..

  49. nice tutorial, thank you..

  50. Pis osse says:

    Any suggestions on how to get captions from a custom field into Jquery?

  51. Asep says:

    Definitly, clear and straighforward useful tutorial !

  52. 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

  53. wanville says:

    it works… thnx

  54. thanks, just use this for one of my site :)

  55. LaCursiva says:

    something does not work for me, I’ll try again, thanks!

  56. Mail House says:

    Really a great tutorial it is easily understandable by anyone new to wordpress as well.

    Thank You.

  57. David Gómez says:

    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?

    • David Gómez says:

      Found the error…

      In the code you give to put in the footer, you call the jquery.nivo.slider.js file, but is the jquery.nivo.slider.pack.js file. I just had to correct this line and everything worked perfectly, thank you for the tutorial.

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

  58. nachitox says:

    nice tutorial, i will put in my blog.

  59. outlet says:

    there be an easier way to implement Nivoslider into themes using the post thumbnails introduced in WordPress 3.0?

  60. 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?

  61. Ajinkya says:

    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 :)

  62. Daniel says:

    Tried to apply the nivo slider to my twenty ten header, but the slider doesn’t work… Followed every step in this tutorial

  63. Erwin says:

    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!!

  64. fever18 says:

    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.

  65. Lukman says:

    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 says:

      What’s wrong with the path?? I don’t see an issue. It is < ?php bloginfo('template_directory'); ?>/jquery.nivo.slider.js and that’s what is there in the tutorial

      • Lukman says:

        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

  66. Keenan Payne says:

    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?

  67. Jason Loucks says:

    Great post. Thanks for this. I was wondering if you could recommend a automatic image resizer script? Thanks.

  68. chris says:

    nice tutorial, or you could use the nivo slider wordpress plugin which makes it easier for novices ;)

    http://wordpress.org/extend/plugins/wp-nivo-slider/

    • Jai says:

      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. :)


Websites that Link to this Post

  1. Installing the Nivo Image Slider in WordPress
  2. Incorporar Nivo Slider en WordPress | Chica Blogger
  3. How to Integrate Nivo Slider into WordPress | Game & Tech :: Latest Game And Tech News from all Around The World
  4. How to Integrate Nivo Slider into WordPress | Blog Oh Blog | Terry J. Barrett's Blog
  5. Desarrollo Link Web » Cómo integrar Nivo Slider en WordPress
  6. Como se usan los Slides en lo Themes?

Leave a comment

Search :