me2arafat

Use nivo slider in wordpress by ShortCode

Dec 16th, 2015
136
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 1.83 KB | None | 0 0
  1. Code in functions.php
  2.  
  3. function nivo_slider_rrf () {
  4.     wp_enqueue_script('jquery');
  5.     wp_enqueue_script( 'nivo_main_file', get_template_directory_uri() . '/js/jquery.nivo.slider.pack.js', array('jquery') );
  6.     wp_enqueue_script( 'nivo_active_file', get_template_directory_uri() . '/js/nivo-slider-active.js', array('jquery') );
  7.     wp_enqueue_style( 'nivo-default-theme', get_template_directory_uri() . '/nivo-slider/themes/default/default.css' );
  8.     wp_enqueue_style( 'nivo-light-theme', get_template_directory_uri() . '/nivo-slider/themes/light/light.css' );
  9.     wp_enqueue_style( 'nivo-dark-theme', get_template_directory_uri() . '/nivo-slider/themes/dark/dark.css' );
  10.     wp_enqueue_style( 'nivo-bar-theme', get_template_directory_uri() . '/nivo-slider/themes/bar/bar.css' );
  11.     wp_enqueue_style( 'nivo-main-css', get_template_directory_uri() . '/nivo-slider/nivo-slider.css' );
  12. }
  13. add_action( 'wp_enqueue_scripts', 'nivo_slider_rrf' );
  14.  
  15.  
  16. function nivo_slider_loop ($atts, $content = null){
  17.  
  18.     extract ( shortcode_atts ( array (
  19.        
  20.         'theme' => 'defult',
  21.     ), $atts, 'slider') );
  22.  
  23.     return '<div class="slider-wrapper theme-'.$theme.'"><div id="slider" class="nivoSlider">' . do_shortcode($content) . '</div></div>';
  24. }
  25. add_shortcode ('slider', 'nivo_slider_loop');
  26.  
  27. function nivo_slides_loop ($atts){
  28.  
  29.     extract ( shortcode_atts ( array (
  30.         'content' => 'null',
  31.         'image' => 'null',
  32.         'title' => 'default',
  33.         'link' => 'http://',
  34.     ), $atts, 'slides') );
  35.  
  36.     return '<a href="'.$link.'"><img src="'.$image.'" data-thumb="'.$image.'" alt="" title="'.$title.'" /></a>';
  37. }
  38. add_shortcode ('slides', 'nivo_slides_loop');
  39.  
  40.  
  41.  
  42. Usage
  43.  
  44. [slider theme="light"][slides image="http://lorempixel.com/600/350/nature/" title="Slider Caption" link="http://wordpress.org"] [slides image="http://placehold.it/600x350" title="Slider Caption" link="http://google.com"][/slider]
Add Comment
Please, Sign In to add comment