* @copyright Copyright (c) 2008 - 2012, Justin Tadlock * @link http://justintadlock.com/archives/2008/04/13/cleaner-wordpress-gallery-plugin * @license http://www.gnu.org/licenses/old-licenses/gpl-2.0.html */ /* Filter the post gallery shortcode output. */ add_filter( 'post_gallery', 'cleaner_gallery', 10, 2 ); /** * Overwrites the default WordPress [gallery] shortcode's output. This function removes the invalid * HTML and inline styles. It adds the number of columns used as a class attribute, which allows * developers to style the gallery more easily. * * @since 0.9.0 * @access private * * @param string $output * @param array $attr * * @return string $output */ if ( ! function_exists( 'cleaner_gallery' ) ) { function cleaner_gallery( $output, $attr ) { static $cleaner_gallery_instance = 0; $cleaner_gallery_instance ++; /* We're not worried abut galleries in feeds, so just return the output here. */ if ( is_feed() ) return $output; /* Orderby. */ if ( isset( $attr['orderby'] ) ) { $attr['orderby'] = sanitize_sql_orderby( $attr['orderby'] ); if ( ! $attr['orderby'] ) unset( $attr['orderby'] ); } /* Default gallery settings. */ $defaults = array( 'order' => 'ASC', 'orderby' => 'menu_order ID', 'id' => get_the_ID(), 'link' => '', 'itemtag' => 'li', 'icontag' => 'div', 'captiontag' => 'div', 'columns' => 3, 'size' => 'thumbnail', 'include' => '', 'exclude' => '', 'numberposts' => - 1, 'offset' => '' ); /* Apply filters to the default arguments. */ $defaults = apply_filters( 'cleaner_gallery_defaults', $defaults ); /* Apply filters to the arguments. */ $attr = apply_filters( 'cleaner_gallery_args', $attr ); /* Merge the defaults with user input. */ $attr = shortcode_atts( $defaults, $attr ); extract( $attr ); $id = intval( $id ); /* Arguments for get_children(). */ $children = array( 'post_parent' => $id, 'post_status' => 'inherit', 'post_type' => 'attachment', 'post_mime_type' => 'image', 'order' => $order, 'orderby' => $orderby, 'exclude' => $exclude, 'include' => $include, 'numberposts' => $numberposts, 'offset' => $offset, 'suppress_filters' => true ); /* Get image attachments. If none, return. */ $attachments = get_children( $children ); if ( empty( $attachments ) ) return ''; /* Properly escape the gallery tags. */ $itemtag = tag_escape( $itemtag ); $icontag = tag_escape( $icontag ); $captiontag = tag_escape( $captiontag ); $i = 0; /* Count the number of attachments returned. */ $attachment_count = count( $attachments ); /* Allow developers to overwrite the number of columns. This can be useful for reducing columns with with fewer images than number of columns. */ //$columns = ( ( $columns <= $attachment_count ) ? intval( $columns ) : intval( $attachment_count ) ); $columns = apply_filters( 'cleaner_gallery_columns', intval( $columns ), $attachment_count, $attr ); /** Convert number to word */ $numbers = array( '1' => 'one', '2' => 'two', '3' => 'three', '4' => 'four', '5' => 'five', '6' => 'six', '7' => 'seven', '8' => 'eight', '9' => 'nine', '10' => 'ten', ); /* Open the gallery
. */ $output = "\n\t\t\t
"; /* Close the gallery
. */ $output .= "\n\t\t\t\n"; /* Return out very nice, valid HTML gallery. */ return $output; } }