Created
October 19, 2017 00:12
-
-
Save bloqhead/7a10549d916c04a4cc43817bf6305826 to your computer and use it in GitHub Desktop.
WordPress media gallery that uses bxSlider.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| /** | |
| * 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; | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment