dragunoff

[WP] post_gallery()

Jan 28th, 2012
240
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 2.34 KB | None | 0 0
  1. <?php
  2. function post_gallery( $p = 0 ) {
  3.    
  4.     // globals
  5.     global $post;
  6.    
  7.     $post_id = ( $p === 0 ) ? $post->ID : $p;
  8.    
  9.     // vars
  10.     $r = $r_list = $r_imgs = '';
  11.     $i = 0;
  12.     $args = array(
  13.         'post_type' => 'attachment',
  14.         'post_mime_type' => 'image',
  15.         'numberposts' => -1,
  16.         'post_status' => null,
  17.         'post_parent' => $post_id
  18.     );
  19.  
  20.     // get attachments
  21.     $attachments = get_posts($args);
  22.    
  23.     // if any
  24.     if ( $attachments ) {
  25.  
  26.         // loop attachments
  27.         foreach ( $attachments as $img ) {
  28.            
  29.             // vars
  30.             $img_thumb_atts = wp_get_attachment_image_src( $img->ID, 'small' );
  31.             $img_full_atts = wp_get_attachment_image_src( $img->ID, 'full' );
  32.             $img_desc = $img->post_excerpt;
  33.            
  34.             // counter
  35.             $i++;
  36.            
  37.             // html for navigation list
  38.             $r_list .= '<li class="item">';
  39.                 $r_list .= '<a href="#" rel="' . $i . '"';
  40.                 if ( $i == 1 )
  41.                     $r_list .= ' class="selected"';
  42.                 $r_list .= '>';
  43.                     $r_list .= '<img src="' . $img_thumb_atts[0] . '" />';
  44.                 $r_list .= '</a>';
  45.             $r_list .= '</li><!-- /.item -->';
  46.        
  47.             // html for the single image
  48.             $r_imgs .= '<div id="' . $i. '" class="photos_viewbox">';
  49.                 $r_imgs .= '<a href="' . $img_full_atts[0] . '" class="single_image" title="">';
  50.                     $r_imgs .= '<img src="' . $img_full_atts[0] . '" alt="" title="" />';
  51.                 $r_imgs .= '</a>';
  52.                 $r_imgs .= '<a href="javascript:photos.cycleit(\'prev\')" class="photos_prev"> </a>';
  53.                 $r_imgs .= '<a href="javascript:photos.cycleit(\'next\')" class="photos_next"> </a>';
  54.                 $r_imgs .= '<p class="photos_number">' . sprintf( __( '%1$s / %2$s' ), $i, count($attachments) ) . '</p>';
  55.                 $r_imgs .= '<p class="photos_number">' . $img_desc . '</p>';
  56.             $r_imgs .= '</div><!-- /.photos_viewbox -->';
  57.         }
  58.        
  59.         // concatenate the html
  60.         $r .= '<div id="gallery-slider">';
  61.             $r .= '<div class="photos-next"></div><div class="photos-prev"></div>';
  62.             $r .= '<div class="carousel-gallery">';
  63.                 $r .= '<ul id="photos" class="photos_thumb">';
  64.                     $r .= $r_list;
  65.                 $r .= '</ul><!-- /#photos -->';
  66.             $r .= '</div><!-- /.carousel-gallery -->';
  67.         $r .= '</div><!-- /#gallery-slider -->';
  68.         $r .= $r_imgs;
  69.         $r .= '<script type="text/javascript">
  70.         var photos=new ddtabcontent("photos")
  71.         photos.setpersist(true)
  72.         photos.setselectedClassTarget("link")
  73.         photos.init()
  74.         </script>';
  75.        
  76.         // print the result
  77.         return $r;
  78.     }
  79. }
Advertisement
Add Comment
Please, Sign In to add comment