Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- function post_gallery( $p = 0 ) {
- // globals
- global $post;
- $post_id = ( $p === 0 ) ? $post->ID : $p;
- // vars
- $r = $r_list = $r_imgs = '';
- $i = 0;
- $args = array(
- 'post_type' => 'attachment',
- 'post_mime_type' => 'image',
- 'numberposts' => -1,
- 'post_status' => null,
- 'post_parent' => $post_id
- );
- // get attachments
- $attachments = get_posts($args);
- // if any
- if ( $attachments ) {
- // loop attachments
- foreach ( $attachments as $img ) {
- // vars
- $img_thumb_atts = wp_get_attachment_image_src( $img->ID, 'small' );
- $img_full_atts = wp_get_attachment_image_src( $img->ID, 'full' );
- $img_desc = $img->post_excerpt;
- // counter
- $i++;
- // html for navigation list
- $r_list .= '<li class="item">';
- $r_list .= '<a href="#" rel="' . $i . '"';
- if ( $i == 1 )
- $r_list .= ' class="selected"';
- $r_list .= '>';
- $r_list .= '<img src="' . $img_thumb_atts[0] . '" />';
- $r_list .= '</a>';
- $r_list .= '</li><!-- /.item -->';
- // html for the single image
- $r_imgs .= '<div id="' . $i. '" class="photos_viewbox">';
- $r_imgs .= '<a href="' . $img_full_atts[0] . '" class="single_image" title="">';
- $r_imgs .= '<img src="' . $img_full_atts[0] . '" alt="" title="" />';
- $r_imgs .= '</a>';
- $r_imgs .= '<a href="javascript:photos.cycleit(\'prev\')" class="photos_prev"> </a>';
- $r_imgs .= '<a href="javascript:photos.cycleit(\'next\')" class="photos_next"> </a>';
- $r_imgs .= '<p class="photos_number">' . sprintf( __( '%1$s / %2$s' ), $i, count($attachments) ) . '</p>';
- $r_imgs .= '<p class="photos_number">' . $img_desc . '</p>';
- $r_imgs .= '</div><!-- /.photos_viewbox -->';
- }
- // concatenate the html
- $r .= '<div id="gallery-slider">';
- $r .= '<div class="photos-next"></div><div class="photos-prev"></div>';
- $r .= '<div class="carousel-gallery">';
- $r .= '<ul id="photos" class="photos_thumb">';
- $r .= $r_list;
- $r .= '</ul><!-- /#photos -->';
- $r .= '</div><!-- /.carousel-gallery -->';
- $r .= '</div><!-- /#gallery-slider -->';
- $r .= $r_imgs;
- $r .= '<script type="text/javascript">
- var photos=new ddtabcontent("photos")
- photos.setpersist(true)
- photos.setselectedClassTarget("link")
- photos.init()
- </script>';
- // print the result
- return $r;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment