Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function tt_gallery_shortcode($attr)
- {
- global $post;
- static $instance = 0;
- $instance++;
- // Allow plugins/themes to override the default gallery template.
- $output = apply_filters('post_gallery', '', $attr);
- if ( $output != '' )
- return $output;
- // We're trusting author input, so let's at least make sure it looks like a valid orderby statement
- if ( isset( $attr['orderby'] ) ) {
- $attr['orderby'] = sanitize_sql_orderby( $attr['orderby'] );
- if ( !$attr['orderby'] )
- unset( $attr['orderby'] );
- }
- extract(shortcode_atts(array(
- 'order' => 'ASC',
- 'orderby' => 'menu_order ID',
- 'id' => $post->ID,
- 'itemtag' => 'li',
- 'icontag' => 'span',
- 'captiontag' => 'div',
- 'columns' => 0,
- 'size' => 'thumbnail'
- ), $attr));
- $id = intval($id);
- $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 '';
- if ( is_feed() ) {
- $output = "\n";
- foreach ( $attachments as $att_id => $attachment )
- $output .= wp_get_attachment_link($att_id, $size, true) . "\n";
- return $output;
- }
- $itemtag = tag_escape($itemtag);
- $captiontag = tag_escape($captiontag);
- $columns = intval($columns);
- $itemwidth = $columns > 0 ? floor(100/$columns) : 100;
- $selector = "gallery-{$instance}";
- $output = apply_filters('gallery_style', "
- <ul class='thumbs noscript'>
- ");
- $i = 0;
- foreach ( $attachments as $id => $attachment ) {
- $link = isset($attr['link']) && 'file' == $attr['link'] ? wp_get_attachment_link($id, $size, false, false) : wp_get_attachment_link($id, $size, false, false);
- $link = str_replace('<a href=', "<a class='thumb' href=", $link);
- $link_title = "<{$captiontag} class='caption'> <div class='image-title'>" . wptexturize($attachment->post_title) . "</div>";
- $link_caption = "<div class='image-excerpt'>" . wptexturize($attachment->post_excerpt) . "</div>";
- $link_description = "<div class='image-description'>" . wptexturize($attachment->post_content) . "</div> </{$captiontag}>";
- $output .= "<{$itemtag}>
- ";
- $output .= "$link
- ";
- $output .= "$link_title
- ";
- $output .= "$link_caption
- ";
- $output .= "$link_description
- ";
- $output .= "</{$itemtag}>
- ";
- if ( $columns > 0 && ++$i % $columns == 0 )
- $output .= '';
- }
- $output .= "
- </ul>\n";
- return $output;
- }
- add_shortcode('gallery', 'tt_gallery_shortcode');
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement