Changeset 203588
- Timestamp:
- 02/09/2010 10:08:59 PM (16 years ago)
- Location:
- gallery-shortcode-style-to-head/trunk
- Files:
-
- 2 edited
-
gallery-shortcode-style-to-head.php (modified) (7 diffs)
-
readme.txt (modified) (2 diffs)
Legend:
- Unmodified
- Added
- Removed
-
gallery-shortcode-style-to-head/trunk/gallery-shortcode-style-to-head.php
r156582 r203588 6 6 Author: Scott Bradford 7 7 Author URI: http://www.scottbradford.us/ 8 Version: 1. 28 Version: 1.3 9 9 10 10 Copyright (c) 2008 Matt Martz (http://sivel.net) (original author) 11 Copyright (c) 2009 Scott Bradford (http://www.scottbradford.us) (current maintainer)11 Copyright (c) 2009-2010 Scott Bradford (http://www.scottbradford.us) (current maintainer) 12 12 13 13 Gallery Shortcode Style to Head is released under the GNU General Public License (GPL) … … 18 18 // http://trac.wordpress.org/attachment/ticket/6380/6380-style.diff 19 19 function gallery_shortcode_style_out ( $attr ) { 20 global $post; 20 global $post, $wp_locale; 21 22 static $instance = 0; 23 $instance++; 21 24 22 25 // Allow plugins/themes to override the default gallery template. 23 $output = apply_filters ( 'post_gallery' , '' , $attr);26 $output = apply_filters('post_gallery', '', $attr); 24 27 if ( $output != '' ) 25 28 return $output; … … 32 35 } 33 36 34 extract ( shortcode_atts ( apply_filters ( 'gallery_defaults' ,array(37 extract(shortcode_atts(array( 35 38 'order' => 'ASC', 36 39 'orderby' => 'menu_order ID', … … 41 44 'columns' => 3, 42 45 'size' => 'thumbnail', 43 ) ) , $attr ) ); 46 'include' => '', 47 'exclude' => '' 48 ), $attr)); 44 49 45 $id = intval ( $id ); 46 $attachments = get_children ( array ( 'post_parent' => $id , 'post_status' => 'inherit' , 'post_type' => 'attachment' , 'post_mime_type' => 'image' , 'order' => $order , 'orderby' => $orderby ) ); 50 $id = intval($id); 51 if ( 'RAND' == $order ) 52 $orderby = 'none'; 47 53 48 if ( empty( $attachments ) ) 54 if ( !empty($include) ) { 55 $include = preg_replace( '/[^0-9,]+/', '', $include ); 56 $_attachments = get_posts( array('include' => $include, 'post_status' => 'inherit', 'post_type' => 'attachment', 'post_mime_type' => 'image', 'order' => $order, 'orderby' => $orderby) ); 57 58 $attachments = array(); 59 foreach ( $_attachments as $key => $val ) { 60 $attachments[$val->ID] = $_attachments[$key]; 61 } 62 } elseif ( !empty($exclude) ) { 63 $exclude = preg_replace( '/[^0-9,]+/', '', $exclude ); 64 $attachments = get_children( array('post_parent' => $id, 'exclude' => $exclude, 'post_status' => 'inherit', 'post_type' => 'attachment', 'post_mime_type' => 'image', 'order' => $order, 'orderby' => $orderby) ); 65 } else { 66 $attachments = get_children( array('post_parent' => $id, 'post_status' => 'inherit', 'post_type' => 'attachment', 'post_mime_type' => 'image', 'order' => $order, 'orderby' => $orderby) ); 67 } 68 69 if ( empty($attachments) ) 49 70 return ''; 50 71 51 72 if ( is_feed() ) { 52 73 $output = "\n"; 53 foreach ( $attachments as $ id => $attachment )54 $output .= wp_get_attachment_link( $id, $size, false) . "\n";74 foreach ( $attachments as $att_id => $attachment ) 75 $output .= wp_get_attachment_link($att_id, $size, true) . "\n"; 55 76 return $output; 56 77 } 57 78 58 $listtag = tag_escape ( $listtag ); 59 $itemtag = tag_escape ( $itemtag ); 60 $captiontag = tag_escape ( $captiontag ); 61 $columns = intval ( $columns ); 62 $itemwidth = $columns > 0 ? floor ( 100/$columns ) : 100; 79 $itemtag = tag_escape($itemtag); 80 $captiontag = tag_escape($captiontag); 81 $columns = intval($columns); 82 $itemwidth = $columns > 0 ? floor(100/$columns) : 100; 63 83 64 $output = " 65 <!-- see gallery_shortcode() in wp-includes/media.php --> 66 <div class='gallery'>"; 84 $selector = "gallery-{$instance}"; 67 85 86 $output = "<!-- see gallery_shortcode() in wp-includes/media.php --> 87 <div id='$selector' class='gallery galleryid-{$id}'>"; 88 89 $i = 0; 68 90 foreach ( $attachments as $id => $attachment ) { 69 91 $link = isset($attr['link']) && 'file' == $attr['link'] ? wp_get_attachment_link($id, $size, false, false) : wp_get_attachment_link($id, $size, true, false); 92 70 93 $output .= "<{$itemtag} class='gallery-item' style='width:{$itemwidth}%'>"; 71 94 $output .= " … … 73 96 $link 74 97 </{$icontag}>"; 75 if ( $captiontag && trim ( $attachment->post_excerpt) ) {98 if ( $captiontag && trim($attachment->post_excerpt) ) { 76 99 $output .= " 77 100 <{$captiontag} class='gallery-caption'> … … 95 118 function gallery_style () { 96 119 97 $ output = apply_filters('gallery_style', "98 <!-- [gallery] shortcode style -->120 $float = $wp_locale->text_direction == 'rtl' ? 'right' : 'left'; 121 $output = apply_filters('gallery_style', "<!-- [gallery] shortcode style --> 99 122 <style type='text/css'> 100 .gallery { 101 margin: auto; 102 } 103 .gallery-item { 104 float: left; 105 margin-top: 10px; 106 text-align: center; 123 .gallery { 124 margin: auto; 107 125 } 108 .gallery img { 109 border: 2px solid #cfcfcf; 110 } 111 .gallery-caption { 112 margin-left: 0; 113 } 114 </style> 115 "); 126 .gallery .gallery-item { 127 float: {$float}; 128 margin-top: 10px; 129 text-align: center; 130 } 131 .gallery img { 132 border: 2px solid #cfcfcf; 133 } 134 .gallery-caption { 135 margin-left: 0; 136 } 137 </style>"); 116 138 117 139 echo $output; … … 136 158 // Tell WordPress what to do 137 159 remove_shortcode ( 'gallery_shortcode' ); // Remove included WordPress [gallery] shortcode function 138 add_shortcode ( 'gallery' , 'gallery_shortcode_style_out' ); // Add n ot[gallery] shortcode function160 add_shortcode ( 'gallery' , 'gallery_shortcode_style_out' ); // Add new [gallery] shortcode function 139 161 add_action ( 'template_redirect' , 'gallery_scan' ); // Add look ahead for [gallery] shortcode 140 162 ?> -
gallery-shortcode-style-to-head/trunk/readme.txt
r183655 r203588 4 4 Requires at least: 2.6 5 5 Tested up to: 2.9 6 Stable tag: 1. 26 Stable tag: 1.3 7 7 8 8 Moves the gallery shortcode styles to the head so it doesn't break XHTML … … 49 49 == Changelog == 50 50 51 = 1. 2.1 (2009-12-16): =52 * Iterated the supported WordPress version to 2.9.51 = 1.3 (2010-02-09): = 52 * Re-Sync with WordPress 2.9 gallery code for support of the new 'include' and 'exclude' options. 53 53 54 54 = 1.2 (2009-09-20): =
Note: See TracChangeset
for help on using the changeset viewer.