greglbd
Forum Replies Created
Viewing 1 replies (of 1 total)
-
Forum: Themes and Templates
In reply to: [Understrap] [gallery] shortcode is not workingHi,
I kinda solved this, it’s a little hacky but uses bootstrap. I actually wanted a carousel rather than thumbs but this is what i have. It seems a few attributes were missing from the
shortcode_attsarray.<?php //Based on Jeff Hays code and his article here: http://robido.com/wordpress/wordpress-gallery-filter-to-modify-the-html-output-of-the-default-gallery-shortcode-and-style/ // Custom filter function to modify default gallery shortcode output // Adapted by Greg Conn of Live Breathe Digital to output a bootstrap carousel. function bootstrap_wp_gallery( $output, $attr ) { // Initialize global $post, $wp_locale; // Gallery instance counter static $instance = 0; $instance++; // Validate the author's orderby attribute if ( isset( $attr['orderby'] ) ) { $attr['orderby'] = sanitize_sql_orderby( $attr['orderby'] ); if ( ! $attr['orderby'] ) unset( $attr['orderby'] ); } // Get attributes from shortcode extract( shortcode_atts( array( 'order' => 'ASC', 'orderby' => 'menu_order ID', 'id' => $post->ID, 'itemtag' => 'div', 'icontag' => 'div', 'captiontag' => 'div', 'columns' => 3, 'size' => 'thumbnail', 'exclude' => '', 'include' => '', 'ids' => '' ), $attr ) ); // Initialize $id = intval( $id ); $attachments = array(); if ( $order == 'RAND' ) $orderby = 'none'; if ( ! empty( $include ) ) { // Include attribute is present $include = preg_replace( '/[^0-9,]+/', '', $include ); $_attachments = get_posts( array( 'include' => $include, 'post_status' => 'inherit', 'post_type' => 'attachment', 'post_mime_type' => 'image', 'order' => $order, 'orderby' => $orderby ) ); // Setup attachments array foreach ( $_attachments as $key => $val ) { $attachments[ $val->ID ] = $_attachments[ $key ]; } } else if ( ! empty( $exclude ) ) { // Exclude attribute is present $exclude = preg_replace( '/[^0-9,]+/', '', $exclude ); // Setup attachments array $attachments = get_children( array( 'post_parent' => $id, 'exclude' => $exclude, 'post_status' => 'inherit', 'post_type' => 'attachment', 'post_mime_type' => 'image', 'order' => $order, 'orderby' => $orderby ) ); } else { // Setup attachments array $attachments = get_children( array( 'post_parent' => $id, 'post_status' => 'inherit', 'post_type' => 'attachment', 'post_mime_type' => 'image', 'order' => $order, 'orderby' => $orderby ) ); } if ( empty( $attachments ) ) return ''; // Filter gallery differently for feeds if ( is_feed() ) { $output = "\n"; foreach ( $attachments as $att_id => $attachment ) $output .= wp_get_attachment_link( $att_id, $size, true ) . "\n"; return $output; } // Filter tags and attributes $itemtag = tag_escape( $itemtag ); $captiontag = tag_escape( $captiontag ); $columns = intval( $columns ); $itemwidth = $columns > 0 ? floor( 12 / $columns ) : 100; $float = is_rtl() ? 'right' : 'left'; $selector = "gallery-{$instance}"; // Filter gallery CSS //<div id='$selector' class='gallery galleryid-{$id} row'>" $output = apply_filters( 'gallery_style', " <div id='gallery-carousel' class='carousel slide galleryid-{$id}' data-ride='carousel'> <div class='carousel-inner' role='listbox' data-link='".isset( $attr['link'] ) ."' data-file='".$attr['link']."'>" ); // Iterate through the attachments in this gallery instance $i = 0; foreach ( $attachments as $id => $attachment ) { // Attachment link $link = isset( $attr['link'] ) && 'file' == $attr['link'] ? wp_get_attachment_link( $id, $size, false, false, false, array('class'=>'carousel-image') ) : wp_get_attachment_link( $id, $size, true, false, false, array('class'=>'carousel-image') ); if(!isset($attr) || (isset( $attr['link'] ) && 'none' == $attr['link'])) { $link = wp_get_attachment_image( $id, $size, false, array('class'=>'carousel-image') ); } // Start itemtag $active = ($i==0 ? 'active' :''); $output .= "<{$itemtag} class='carousel-item {$active}'>"; // icontag $output .= " $link "; if ( $captiontag && trim( $attachment->post_excerpt ) ) { // captiontag $output .= " <{$captiontag} class='carousel-caption'> " . wptexturize($attachment->post_excerpt) . " </{$captiontag}>"; } // End itemtag $output .= "</{$itemtag}>"; // Line breaks by columns set //if($columns > 0 && ++$i % $columns == 0) $output .= '<br style="clear: both">'; ++$i; } // End gallery output $output .= " <a class='left carousel-control' href='#gallery-carousel' role='button' data-slide='prev'> <span class='fa fa-angle-left' aria-hidden='true'></span> <span class='sr-only'>Previous</span> </a> <a class='right carousel-control' href='#gallery-carousel' role='button' data-slide='next'> <span class='fa fa-angle-right' aria-hidden='true'></span> <span class='sr-only'>Next</span> </a> </div></div>\n"; return $output; } // Apply filter to default gallery shortcode add_filter( 'post_gallery', 'bootstrap_wp_gallery', 10, 2 );
Viewing 1 replies (of 1 total)