bloqhead
10/19/2017 - 12:12 AM

WordPress media gallery that uses bxSlider.

WordPress media gallery that uses bxSlider.

/**
 * Custom media gallery output
 */
add_filter( 'post_gallery', 'big_sea_custom_post_gallery', 10, 2 );
remove_shortcode('gallery');
add_shortcode('gallery', 'big_sea_custom_post_gallery');

function big_sea_custom_post_gallery( $atts ) {
	global $post;
	$pid = $post->ID;
	$gallery = "";

	if ( empty($pid) ) {
		$pid = $post['ID'];
	}

	if ( !empty( $atts['ids'] ) ) {
   	$atts['orderby'] = 'post__in';
   	$atts['include'] = $atts['ids'];
	}

	extract(
		shortcode_atts(
			array(
				'orderby' => 'menu_order ASC, ID ASC',
				'include' => '',
				'id' => $pid,
				'itemtag' => 'dl',
				'icontag' => 'dt',
				'captiontag' => 'dd',
				'columns' => 3,
				'size' => 'large',
				'link' => 'file'
			),
		$atts)
	);

	$args = array(
		'post_type' => 'attachment',
		'post_status' => 'inherit',
		'post_mime_type' => 'image',
		'orderby' => $orderby
	);

	if (!empty($include)) {
		$args['include'] = $include;
	}
	else {
   	$args['post_parent'] = $id;
		$args['numberposts'] = -1;
	}

	if ( $args['include'] == "" ) {
		$args['orderby'] = 'date'; $args['order'] = 'asc';
	}

	$images = get_posts($args);

	ob_start(); ?>

	<div class="media-carousel">

		<div class="media-carousel__main-images">
		<?php foreach ( $images as $image ) :
			$thumbnail = wp_get_attachment_image_src( $image->ID, 'eckerd-media-lrg' );
			$thumbnail = $thumbnail[0];
		?>
			<img class="media-carousel__item--main" src="<?= $thumbnail ?>" alt="<?= $image->post_title ?>">
		<?php endforeach; ?>
		</div>

		<div class="media-carousel__thumbnails">
		<?php
		$i = 0;
		foreach ( $images as $image ) :
			$thumbnail = wp_get_attachment_image_src( $image->ID, 'eckerd-media-sml' );
			$thumbnail = $thumbnail[0];
			$i++;
		?>
			<a href="#" class="media-carousel__item--thumb" data-slide-index="<?= $i ?>">
				<img src="<?= $thumbnail ?>" alt="<?= $image->post_title ?>">
			</a>
		<?php endforeach; ?>
		</div>

	</div>

	<?php
	$output = ob_get_contents();
	ob_end_clean();

	return $output;
}