Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*--------------------------------------*/
- /* WPEX Gallery
- /*--------------------------------------*/
- function wpex_gallery_shortcode( $atts, $content = null ) {
- extract( shortcode_atts( array(
- 'columns' => '4',
- 'image_height' => '',
- 'exclude' => '',
- 'lightbox' => ''
- ), $atts ) );
- $output = '';
- global $post;
- //get attachement count
- $get_attachments = get_children( array( 'post_parent' => $post->ID ) );
- //get ID of featured image
- $featured_image_id = get_post_thumbnail_id( $post->ID );
- //generate random number for each gallery
- $rand_gallery = rand();
- //attachement loop
- $args = array(
- 'orderby' => 'menu_order',
- 'post_type' => 'attachment',
- 'post_parent' => get_the_ID(),
- 'post_mime_type' => 'image',
- 'post_status' => null,
- 'posts_per_page' => -1,
- 'exclude' => $exclude
- );
- $attachments = get_posts($args);
- //show gallery only if attachments exist
- if ($attachments) {
- $output .= '<article class="gallery-wrap grid-container clearfix">';
- //start attachment loop
- foreach ($attachments as $attachment) :
- //featured image
- ($image_height) ? $image_attach_height = 450 * str_replace('%', '', $image_height) / 100 : $image_attach_height = 450;
- $thumb = $attachment->ID;
- $img_url = wp_get_attachment_url($thumb,'full'); //get full URL to image
- $featured_image = aq_resize( $img_url, 450, $image_attach_height, true ); //resize & crop the image
- //output image
- $output .='<div class="gallery-photo grid-'.$columns.'">';
- $output .= '<a href="'. $img_url .'" class="single-gallery-thumb"';
- if($lightbox !='no'){
- $output .= 'rel="prettyPhoto['.$rand_gallery.']"';
- }
- $output .= 'title="'. apply_filters('the_title', $attachment->post_title) .'"><img src="'. $featured_image .'" alt="'. apply_filters('the_title', $attachment->post_title) .'" class="attachment-post-thumbnail" /></a>';
- $output .='</div>';
- //end loop
- endforeach;
- $output .='</article>';
- }
- return $output;
- }
- add_shortcode( 'wpex_gallery', 'wpex_gallery_shortcode' );
Advertisement
Add Comment
Please, Sign In to add comment