Advertisement
nlozovan

Untitled

Apr 7th, 2014
74
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 7.73 KB | None | 0 0
  1. /*generates content for gallery slider when 'sly' mode is set*/
  2. static function get_post_img_slideshow($post_id, $size="gallery_format_slider"){
  3.  
  4. /*check the meta data where the attached image ids are stored*/
  5.  
  6. $post_image_gallery_meta = get_post_meta( $post_id, '_post_image_gallery', true );
  7.  
  8. if(strlen($post_image_gallery_meta) && 'Array' != $post_image_gallery_meta){
  9. $product_image_gallery = $post_image_gallery_meta;
  10.  
  11. $img_id_array = array_filter( explode( ',', $product_image_gallery ) );
  12. }else{
  13. //backward compatibility with version prev to 1.1
  14. $attachet_gallery_ids = meta::get_meta( $post_id, 'imagesattached' );
  15.  
  16. if(isset($attachet_gallery_ids['img_ids']) && strlen($attachet_gallery_ids['img_ids'])){
  17. /*mata is stored as a string of numbers separated by comma (ex: 909,914,913,912,911,910,908)*/
  18. $img_id_array = explode(',', $attachet_gallery_ids['img_ids']); //create an array from the string
  19.  
  20.  
  21. }
  22. }
  23.  
  24.  
  25. if(isset($img_id_array) && is_array($img_id_array)){
  26. foreach ($img_id_array as $value) {
  27. $attachments[$value] = $value; // create attachments array in hte format that will work for us
  28. }
  29. }
  30.  
  31.  
  32. if(!isset($attachments)){ // if no meta is attached to the post then the gallery wil be created from attached images
  33. $thumb_ID = get_post_thumbnail_id($post_id);
  34. $attachments = get_children(array('post_parent' => $post_id,
  35. 'post_status' => 'inherit',
  36. 'post_type' => 'attachment',
  37. 'post_mime_type' => 'image',
  38. 'order' => 'ASC',
  39. 'exclude' => $thumb_ID,
  40. 'orderby' => 'menu_order ID'));
  41. }
  42.  
  43.  
  44.  
  45.  
  46. if(count($attachments) > 0){
  47. ?>
  48. <div class="entry-header" >
  49. <div class="frame" id="centered">
  50.  
  51. <ul class="clearfix">
  52. <?php
  53. $pretty_colection_id = mt_rand(0,9999);
  54.  
  55. if($size== "gallery_format_slider"){
  56. $images_to_show_first = 9;
  57. }else{
  58. $images_to_show_first = 5;
  59. }
  60.  
  61. $additional_items = ''; /*in this string we will store the images that are left after loading the number of images defined in $images_to_show_first var*/
  62. $counter = 0;
  63. foreach($attachments as $att_id => $attachment) {
  64. $full_img_url = wp_get_attachment_url($att_id);
  65.  
  66. $thumbnail_url = aq_resize( $full_img_url, get_aqua_size($size), get_aqua_size($size, 'height'), false, false ); //resize img, Return an array containing url, width, and height.
  67.  
  68. //$thumbnail_url= wp_get_attachment_image_src( $att_id, $size);
  69.  
  70. $alt = get_post_meta($att_id, '_wp_attachment_image_alt', true);
  71.  
  72.  
  73. if($counter < $images_to_show_first){
  74. $src = $thumbnail_url[0]; // for the first X images we will give original img src
  75. }else{
  76. $src = get_template_directory_uri().'/images/grey.gif'; // for the rest of the images we will load a 1px image to not load the page
  77. }
  78.  
  79. //$caption = image::caption( $att_id );
  80. $attachment_info = get_post($att_id); //deb::e($attachment_info );
  81. $caption = $alt;
  82.  
  83. global $wp_query;
  84. $post_now = $wp_query -> queried_object;
  85.  
  86.  
  87. ob_start();
  88. ob_clean();
  89.  
  90. ?>
  91. <li class="relative">
  92.  
  93. <?php if (options::logic('blog_post', 'show_sly_caption') && meta::logic( $post_now , 'gallerytype' , 'show_sly_caption' )) { ?>
  94. <div class="sly-caption"><?php echo $caption; ?></div>
  95. <?php }?>
  96.  
  97. <img class="lazy" src="<?php echo $src; ?>" data-original="<?php echo $thumbnail_url[0]; ?>" alt="<?php echo $caption; ?>" width="<?php echo $thumbnail_url[1]; ?>" height="<?php echo $thumbnail_url[2]; ?>" data-width="<?php echo $thumbnail_url[1]; ?>" data-height="<?php echo $thumbnail_url[2]; ?>" alt="" />
  98.  
  99. <?php if( options::logic( 'blog_post' , 'enb_lightbox' )){ ?>
  100. <div class="zoom-image">
  101. <a href="<?php echo $full_img_url; ?>" data-rel="prettyPhoto[<?php echo $pretty_colection_id; ?>]" title="<?php echo $caption; ?>">&nbsp;</a>
  102. </div>
  103. <?php } if (options::logic('styling', 'stripes')) { ?>
  104. <div class="stripes" >&nbsp;</div>
  105. <?php }?>
  106. </li>
  107. <?php
  108. $li_item = ob_get_clean();
  109.  
  110. if($counter < $images_to_show_first){
  111. // we output the first X images
  112. $src = $thumbnail_url[0];
  113. echo $li_item;
  114. }else{
  115. // the other images are stored into a string
  116. $additional_items .= $li_item;
  117.  
  118. }
  119. $counter++;
  120. }
  121. ?>
  122. </ul>
  123. <?php
  124. if( strlen( $additional_items) ){
  125. //if there are any images in the additional items, then we will create a hidded DIV with this images
  126. echo '<div class="additional_items" style="display:none">'.$additional_items.'</div>';
  127. }
  128. ?>
  129. </div>
  130. <div class="scrollbar">
  131. <div class="handle">
  132. <div class="mousearea"></div>
  133. </div>
  134. </div>
  135. <div class="controls center">
  136. <button class="btn prev"><i class="icon-prev"></i></button>
  137. <button class="btn next"><i class="icon-next"></i></button>
  138. </div>
  139. </div>
  140. <?php
  141. }else{
  142. ?>
  143. <div class="entry-header noimages" >
  144. <div class="frame" id="centered">
  145. <h3><?php _e('There are no images attached to this gallery','cosmotheme'); ?></h3>
  146.  
  147. </div>
  148. </div>
  149. <?php
  150. }
  151.  
  152. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement