jacodelucia
3/1/2015 - 10:03 AM

WP - Custom Gallery

WP - Custom Gallery

<?php
remove_shortcode('gallery');
add_shortcode('gallery', 'parse_gallery_shortcode');

function parse_gallery_shortcode($atts) {
 
    global $post;
 
    if ( ! empty( $atts['ids'] ) ) {
        // 'ids' is explicitly ordered, unless you specify otherwise.
        if ( empty( $atts['orderby'] ) )
            $atts['orderby'] = 'post__in';
        $atts['include'] = $atts['ids'];
    }
	
    extract(shortcode_atts(array(
        'orderby' => 'menu_order ASC, ID ASC',
        'include' => '',
        'id' => $post->ID,
        'itemtag' => 'dl',
        'icontag' => 'dt',
        'captiontag' => 'dd',
        'columns' => 3,
        'size' => 'medium',
        'link' => 'file'
    ), $atts));
	
	
    $args = array(
        'post_type' => 'attachment',
        'post_status' => 'inherit',
        'post_mime_type' => 'image',
        'orderby' => 'post__in'
    );
 
    if ( !empty($include) )
        $args['include'] = $include;
    else {
        $args['post_parent'] = $id;
        $args['numberposts'] = -1;
    }
	
    $images = get_posts($args);
	
	$output = '<div id="postGallery">';
	$output .= '<div id="prevGallerySlide">Précédent</div>';
	$output .= '<div id="nextGallerySlide">Suivant</div>';
	$output .= '<div id="gallery_mins" class="mTop20 mBot10">';
	$i=0;
	$mins = '';
	foreach( $images as $image ):
		$image_url = wp_get_attachment_image_src($image->ID, 'thumbnail');
		$mins .= '<div class="item';
		if($i == 0) $mins .=  ' active';
		$mins .= '"><div class="hover"></div>';
		$mins .= '<a href="#galleryImage'.$image->ID.'">';
		$mins .= '<img src="'.$image_url[0].'" alt="'.$image->post_title.'" />';
		$mins .= '</a></div>';
		$i++;
	endforeach;
	$output .= $mins;
	$output .= '</div>';
	$output .= '<div id="gallery_view">';
	$i=0;
	$bigs = '';
	foreach ( $images as $image ) :
		$image_url = wp_get_attachment_image_src($image->ID, 'gallery');
		$bigs .= '<div id="galleryImage'.$image->ID.'" class="image';
		if($i == 0) $bigs .= ' active'; 
		$bigs .= '">';
		$bigs .= '<img src="'.$image_url[0].'" alt="'.$image->post_title.'" />';
		$bigs .= '<h3>'.$image->post_title.'</h3>';
		$bigs .= '<p>'.$image->post_excerpt.'</p>';
		$i++;
		$bigs .= '</div>';
	endforeach;
	$output .= $bigs;
	$output .= '</div></div>';

    return $output;
}