Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- // adds thickbox to all images embedded in a post from the media library including galleries
- add_filter('the_content', 'brentini_addthickboxclass');
- function brentini_addthickboxclass($content) {
- add_thickbox();
- $pattern[0] ="/<a(.*?)href=('|\")(.*?).(bmp|gif|jpeg|jpg|png)('|\")(.*?)>/i";
- $replacement[0] = '<a$1href=$2$3.$4$5 class="thickbox">';
- $pattern[1] = "/(<a href=)('|\")([^\>]*?)(\.bmp|\.gif|\.jpg|\.jpeg|\.png)('|\")([^\>]*?)(>)(.*?) title=('|\")(.*?)('|\")(.*?)(<\/a>)/i";
- $replacement[1] = '$1$2$3$4$5$6 title=$9$10$11$7$8 title=$9$10$11$12$13';
- $pattern[2] = "/(<a href=)('|\")([^\>]*?)(\.bmp|\.gif|\.jpg|\.jpeg|\.png)('|\")([^\>]*?) title=([^\>]*?) title=([^\>]*?)(>)(.*?)(<\/a>)/i";
- $replacement[2] = '$1$2$3$4$5$6 title=$7$9$10$11';
- $content = preg_replace($pattern, $replacement, $content);
- return $content;
- }
- function gallery_shortcode_tbi($attr) {
- global $post;
- if ( isset( $attr['orderby'] ) ) {
- $attr['orderby'] = sanitize_sql_orderby( $attr['orderby'] );
- if ( !$attr['orderby'] )
- unset( $attr['orderby'] );
- }
- extract(shortcode_atts(array(
- 'orderby' => 'menu_order ASC, ID ASC',
- 'id' => $post->ID,
- 'itemtag' => 'dl',
- 'icontag' => 'dt',
- 'captiontag' => 'dd',
- 'columns' => 3,
- 'size' => 'thumbnail',
- ), $attr));
- $id = intval($id);
- $attachments = get_children("post_parent=$id&post_type=attachment&post_mime_type=image&orderby={$orderby}");
- if ( empty($attachments) )
- return '';
- if ( is_feed() ) {
- $output = "\n";
- foreach ( $attachments as $id => $attachment )
- $output .= wp_get_attachment_link($id, $size, true) . "\n";
- return $output;
- }
- $itemtag = tag_escape($itemtag);
- $captiontag = tag_escape($captiontag);
- $columns = intval($columns);
- $itemwidth = $columns > 0 ? floor(100/$columns) : 100;
- $output = apply_filters('gallery_style', "
- <style type='text/css'>
- .gallery {
- margin: auto;
- }
- .gallery-item {
- float: left;
- margin-top: 10px;
- text-align: center;
- width: {$itemwidth}%; }
- .gallery img {
- border: 2px solid #cfcfcf;
- }
- .gallery-caption {
- margin-left: 0;
- }
- </style>
- <div class='gallery'>");
- foreach ( $attachments as $id => $attachment ) {
- $a_img = wp_get_attachment_url($id);
- $att_page = get_attachment_link($id);
- $img = wp_get_attachment_image_src($id, $size);
- $img = $img[0];
- $title = $attachment->post_excerpt;
- if($title == '') $title = $attachment->post_title;
- $output .= "<{$itemtag} class='gallery-item'>";
- $output .= "
- <{$icontag} class='gallery-icon'>
- <a href=\"$a_img\" title=\"$title\" class=\"thickbox\" rel=\"gallery-$post->ID\">
- <img src=\"$img\" alt=\"$title\" />
- </a>
- </{$icontag}>";
- if ( $captiontag && trim($attachment->post_excerpt) ) {
- $output .= "
- <{$captiontag} class='gallery-caption'>
- {$attachment->post_excerpt}
- </{$captiontag}>";
- }
- $output .= "</{$itemtag}>";
- if ( $columns == 0 )
- $output .= '<br style="clear: both" />';
- }
- $output .= "
- <br style='clear: both;' />
- </div>\n";
- return $output;
- }
- remove_shortcode('gallery');
- add_shortcode('gallery', 'gallery_shortcode_tbi');
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement