nggShowSlideshow

Wrapper to I_Displayed_Gallery_Renderer->display_images(); this will display a basic slideshow gallery.

Description

(string) nggShowSlideshow( (int) $galleryID, (constant) $args = null ); 

Returns (string)

The HTML code for the slideshow.

Parameters (2)

0. $galleryid (int)
ID of the gallery.
1. $args — Optional. (constant) => null
An array of options.

Usage

  1. if ( !function_exists( 'nggShowSlideshow' ) ) { 
  2. require_once ABSPATH . PLUGINDIR . 'nextcellent-gallery/nggfunctions.php'; 
  3.  
  4. // ID of the gallery. 
  5. $galleryid = -1; 
  6.  
  7. // (optional) An array of options. 
  8. $args = null; 
  9.  
  10. // NOTICE! Understand what this does before running. 
  11. $result = nggShowSlideshow($galleryid, $args); 
  12.  

Defined (1)

The function is defined in the following location(s).

/nggfunctions.php  
  1. function nggShowSlideshow( $galleryID, $args = null) { 
  2.  
  3. global $slideCounter, $nggdb, $ngg; 
  4. $ngg_options = $ngg->options; 
  5.  
  6. // remove media file from RSS feed 
  7. if ( is_feed() ) { 
  8. $out = '[' . nggGallery::i18n($ngg_options['galTextSlide']) . ']'; 
  9. return $out; 
  10.  
  11. // we need to know the current page id 
  12. if ( !get_the_ID() ) { 
  13. $current_page = rand( 5, 15 ); 
  14. } else { 
  15. $current_page = get_the_ID(); 
  16. // look for a other slideshow instance 
  17. if ( !isset( $slideCounter ) ) $slideCounter = 0; 
  18.  
  19. // create unique anchor 
  20. $anchor = 'ngg_slideshow' . $galleryID . $current_page . $slideCounter++; 
  21.  
  22. $param = wp_parse_args( $args, array( 
  23. 'width' => $ngg_options['irWidth'],  
  24. 'height' => $ngg_options['irHeight'],  
  25. 'class' => 'ngg-slideshow',  
  26. 'anchor' => 'ngg_slideshow' . $galleryID . $current_page . $slideCounter++,  
  27. 'time' => $ngg_options['irRotatetime']*1000,  
  28. 'loop' => $ngg_options['irLoop'],  
  29. 'drag' => $ngg_options['irDrag'],  
  30. 'nav' => $ngg_options['irNavigation'],  
  31. 'nav_dots' => $ngg_options['irNavigationDots'],  
  32. 'autoplay' => $ngg_options['irAutoplay'],  
  33. 'hover' => $ngg_options['irAutoplayHover'],  
  34. 'effect' => $ngg_options['slideFx'],  
  35. 'click' => $ngg_options['irClick'],  
  36. 'autodim' => $ngg_options['irAutoDim'],  
  37. 'number' => $ngg_options['irNumber'] 
  38. )); 
  39.  
  40. /** 
  41. * Edit the args for a NextCellent slideshow. 
  42. * @since 1.9.25beta2 
  43. * @param array $args { 
  44. * All the arguments. 
  45. * @var int $width The width of the slideshow. Will be ignored if $autodim is true. 
  46. * @var int $height The height of the slideshow. Will be ignored if $autodim is set. 
  47. * @var string $class The class that will be assigned to the div containing the slideshow. 
  48. * @var string $anchor The id that will be assigned to the div containing the slideshow. 
  49. * @var int $time The duration of a slide in milliseconds. 
  50. * @var bool $loop If the slideshow should loop. 
  51. * @var bool $drag If the user can drag through the images. 
  52. * @var bool $nav If the navigation elements (next/previous) should be shown. 
  53. * @var bool $nav_dots If the navigation dots should be shown. 
  54. * @var bool $autoplay If the slideshow should automatically start. 
  55. * @var bool $hover If the slideshow should pause when hovering over it. 
  56. * @var string $effect With which effect the slideshow should use. 
  57. * @var bool $click If the slideshow should go to the next image on click. 
  58. * @var bool $autodim If the slideshow should automatically fit (responsive). When true, this will 
  59. * ignore the $width and $height. 
  60. * @var int $number The number of images that should be displayed. Only works when the gallery ID 
  61. * is set to random or recent. 
  62. * } 
  63. */ 
  64. $param = apply_filters( 'ngg_slideshow_args', $param ); 
  65.  
  66. //Get the images 
  67. if ($galleryID == 'random') { 
  68. $images = nggdb::get_random_images( $param['number'] ); //random images 
  69. } elseif ($galleryID == 'recent') { 
  70. $images = nggdb::find_last_images(0 , $param['number'] ); //the last images 
  71. } else { 
  72. $images = $nggdb->get_gallery($galleryID); //a gallery 
  73.  
  74. if( empty($images) ) { 
  75. throw new NGG_Not_Found( __( "The gallery was not found.", 'nggallery' ) ); 
  76.  
  77. $out = '<div class="slideshow"><div id="' . $param['anchor'] . '" class="' . $param['class'] . ' owl-carousel" '; 
  78.  
  79. if( !$param['autodim'] ) { 
  80. $out .= 'style="max-width: ' . $param['width'] . 'px; max-height: ' . $param['height'] . 'px;"'; 
  81. $out .= '>'; 
  82.  
  83. foreach ( $images as $image ) { 
  84. if( !$param['autodim'] ) { 
  85. $out .= '<img src="' . $image->imageURL .'" alt="' . $image->alttext . '" style="max-width: ' . $param['width'] . 'px; max-height: ' . $param['height'] . 'px; width: auto; height:auto; margin:auto">'; 
  86. } else { 
  87. $out .= '<img src="' . $image->imageURL .'" alt="' . $image->alttext . '" >'; 
  88.  
  89. $out .= '</div></div>'."\n"; 
  90. $out .= "\n".'<script type="text/javascript">'; 
  91. $out .= "jQuery(document).ready(function($) { 
  92. var owl = $('#" . $param['anchor'] . "'); 
  93. owl.owlCarousel({ 
  94. items: 1,  
  95. autoHeight: " . var_export($param['autodim'], true) . ", "; 
  96. if ( $param['nav'] ) { 
  97. $out .= "nav: true,  
  98. navText: ['" . __('previous', 'nggallery') ."', '" . __('next', 'nggallery') ."'], "; 
  99. $out .= " 
  100. dots: " . var_export($param['nav_dots'], true) .",  
  101. autoplay: ". var_export($param['autoplay'], true) .",  
  102. autoplayTimeout: " . $param['time'] . ",  
  103. autoplayHoverPause: " . var_export($param['hover'], true) . ",  
  104. animateIn: '" . $param['effect'] . "',  
  105. animateOut: 'fadeOut',  
  106. loop: " . var_export($param['loop'], true) . ",  
  107. mouseDrag: " . var_export($param['drag'], true) .",  
  108. touchDrag: " . var_export($param['drag'], true) . " 
  109. });"; 
  110. if ( $param['click'] ) { 
  111. $out .= "\n" . "owl.click( function () { 
  112. owl.trigger( 'next.owl.carousel' ); 
  113. } );"; 
  114. $out .= "});"; 
  115.  
  116. $out .= "\n" . '</script>'; 
  117.  
  118. return $out;