Changeset 801594
- Timestamp:
- 11/09/2013 02:51:09 PM (12 years ago)
- Location:
- easy-image-display/trunk
- Files:
-
- 3 edited
-
readme.txt (modified) (6 diffs)
-
sb-easy-image-display.php (modified) (13 diffs)
-
sb-easy-image-widget.php (modified) (8 diffs)
Legend:
- Unmodified
- Added
- Removed
-
easy-image-display/trunk/readme.txt
r791858 r801594 3 3 Tags: image, gallery, latest image, random image 4 4 Requires at least: 3.5 5 Tested up to: 3. 6.15 Tested up to: 3.7.1 6 6 Stable tag: trunk 7 7 License: GPLv2 or later … … 19 19 Current features include: 20 20 21 * Include/exclude images based on ID 21 22 * Widget, shortcode and template tag for maximum flexibility 22 23 * Display images at various sizes … … 27 28 Features soon to be added: 28 29 29 * Include/exclude images based on ID 30 * Include/exclude only images associated with content, or only used as feature images 30 * Filter images by attachment status 31 31 * Slideshow layout 32 32 * Custom image sizes … … 80 80 == Installation == 81 81 82 1. Upload the ' sb-easy-image-display' folder to the '/wp-content/plugins/' directory82 1. Upload the 'easy-image-display' folder to the '/wp-content/plugins/' directory 83 83 2. Activate the plugin through the 'Plugins' menu in WordPress 84 84 3. Add images using the widget, shortcode or template tag … … 98 98 == Changelog == 99 99 100 = 1.01 = 100 = 1.0.2 = 101 * Added option to include/exclude images based on ID 102 * Fixed issue with widget form not expanding correctly 103 104 = 1.0.1 = 101 105 * Fixed an incompatibility with other lightbox plugins 102 106 … … 106 110 == Upgrade Notice == 107 111 108 = 1.01 = 112 = 1.0.2 = 113 * New feature! Include/exclude images based on ID. 114 115 = 1.0.1 = 109 116 Fixes an incompatibility with other lightbox plugins. -
easy-image-display/trunk/sb-easy-image-display.php
r791878 r801594 4 4 Plugin URI: http://shellbotics.com/wordpress-plugins/easy-image-display/ 5 5 Description: An easy way to display random or latest images on your site. 6 Version: 1.0 16 Version: 1.0.2 7 7 Author: Shellbot 8 8 Author URI: http://shellbotics.com … … 83 83 'link' => 'file', 84 84 'columns' => '3', 85 'filter' => 'only', 85 86 ), $args ) ); 86 87 … … 92 93 'link' => $link, 93 94 'columns' => $columns, 95 'filter' => $filter, 96 'ids' => $args['ids'], 94 97 ); 95 98 … … 108 111 'link' => 'file', 109 112 'columns' => '3', 113 'filter' => 'only', 110 114 ), $args ) ); 111 115 … … 117 121 'link' => $link, 118 122 'columns' => $columns, 123 'filter' => $filter, 124 'ids' => $args['ids'], 119 125 ); 120 126 … … 133 139 'link' => 'file', 134 140 'columns' => '5', 141 'filter' => 'only', 135 142 ), $args ) ); 136 143 … … 142 149 'link' => $link, 143 150 'columns' => $columns, 151 'filter' => $filter, 152 'ids' => $args['ids'], 144 153 ); 145 154 … … 150 159 /* Construct query and return array of images ------------------------------- */ 151 160 152 function sb_get_easy_image( $args, $src = '' ) { 161 function sb_get_easy_image( $args, $src = '' ) { 153 162 154 163 $query = array ( … … 158 167 159 168 if( $args['num'] ) { 160 $query[' numberposts'] = $args['num'];169 $query['posts_per_page'] = $args['num']; 161 170 } 162 171 … … 170 179 break; 171 180 }; 172 173 $attachments = get_posts( $query ); 181 182 if( $args['ids'] && strtolower( $args['filter'] ) == 'include' ) { 183 $attachments = $this->include_action( $args, $query ); 184 } elseif( $args['ids'] ) { 185 $ids = split( ',', $args['ids'] ); 186 187 if( strtolower( $args['filter'] ) == 'exclude' ) { 188 $query['post__not_in'] = $ids; 189 } else { 190 //Default "only" 191 $query['post__in'] = $ids; 192 } 193 194 $attachments = get_posts( $query ); 195 } else { 196 $attachments = get_posts( $query ); 197 } 174 198 175 199 if ( $attachments ) { … … 177 201 $ids = ''; 178 202 foreach ( $attachments as $attachment ) { 179 $ids .= $attachment->ID .', ';203 $ids .= $attachment->ID . ', '; 180 204 } 181 205 return do_shortcode( '[gallery columns="' . $args['columns'] . '" ids="' . $ids . '" size="' . strtolower( $args['size'] ) . '" link="' . strtolower( $args['link'] ) . '"]' ); … … 185 209 } 186 210 211 } 212 213 214 /* Rejig query based on action parameter -------------------------------- */ 215 function include_action( $args, $query ) { 216 217 $ids = split( ',', $args['ids'] ); 218 219 if( count( $ids ) >= $args['num'] ) { 220 //Equal or more IDs than total images. 221 $query['post__in'] = $ids; 222 223 $attachments = get_posts( $query ); 224 } else { 225 //Less IDs than total images. 226 $diff = $args['num'] - count( $ids ); 227 228 //Original query continues, but number changed to difference 229 //Excludes specified IDs 230 $query['posts_per_page'] = $diff; 231 $query['post__not_in'] = $ids; 232 233 $attachments = get_posts( $query ); 234 wp_reset_postdata(); 235 236 //new query retrieves specified IDs 237 $include = array( 238 'post_type' => 'attachment', 239 'post_mime_type' => 'image', 240 'posts_per_page' => count( $ids ), 241 'post__in' => $ids, 242 ); 243 $included = get_posts( $include ); 244 245 //smoosh all posts together 246 $all = array_merge( $attachments, $included ); 247 248 //order by whatever they were supposed to be ordered by 249 switch( strtolower( $args['order'] ) ) { 250 case 'newest': 251 $sort = SORT_DESC; 252 break; 253 254 case 'oldest': 255 $sort = SORT_ASC; 256 break; 257 258 default: 259 $sort = 'random'; 260 break; 261 } 262 263 if( $sort == 'random' ) { 264 shuffle( $all ); 265 } else { 266 267 $date = array(); 268 269 foreach( $all as $key => $row ) { 270 $date[$key] = $row->post_date; 271 } 272 array_multisort( $date, $sort, $all ); 273 274 } 275 276 //return 277 return $all; 278 279 } 280 281 return $attachments; 187 282 } 188 283 … … 225 320 function sb_easy_image_widget_js() { 226 321 echo "<script type='text/javascript'> 227 window.onload = init; 228 229 function init(){ 230 jQuery('.widget-inside').on( 'click', '#sb-easy-image-advanced-toggle', function () { 231 jQuery(this).siblings('#sb-easy-image-advanced').toggle(); 232 }); 322 function sb_advanced_toggle(el){ 323 jQuery(el).siblings('#sb-easy-image-advanced').toggle(); 233 324 } 234 235 325 </script>"; 236 326 } -
easy-image-display/trunk/sb-easy-image-widget.php
r791878 r801594 2 2 /** 3 3 * Widget Name: Easy Image Display 4 * Version: 1.0 14 * Version: 1.0.2 5 5 */ 6 6 … … 45 45 $instance['columns'] = $new_instance['columns']; 46 46 $instance['link'] = $new_instance['link']; 47 $instance['filter'] = $new_instance['filter']; 48 $instance['ids'] = $new_instance['ids']; 47 49 48 50 return $instance; … … 54 56 55 57 $params = array( 56 'include' => array (58 'include' => array( 57 59 'Show all', 58 60 'Include only', 59 61 'Exclude', 60 62 ), 61 'yesno' => array (63 'yesno' => array( 62 64 'Yes', 63 65 'No', 64 66 ), 65 'order' => array (67 'order' => array( 66 68 'Newest', 67 69 'Oldest', 68 70 'Random', 69 71 ), 70 'sizes' => array (72 'sizes' => array( 71 73 'Thumbnail', 72 74 'Medium', … … 74 76 'Full', 75 77 ), 76 'link' => array (78 'link' => array( 77 79 'None', 78 80 'Lightbox', 79 81 'Attachment', 80 82 'File', 81 ) 83 ), 84 'filter' => array( 85 'Only', 86 'Include', 87 'Exclude', 88 ), 82 89 ); 83 90 … … 98 105 'link' => 'File', 99 106 'columns' => 1, 107 'filter' => 'Only', 100 108 ); 101 109 … … 132 140 </p> 133 141 134 <a id="sb-easy-image-advanced-toggle" href="#" >Advanced settings</a>142 <a id="sb-easy-image-advanced-toggle" href="#" onclick="javascript:sb_advanced_toggle( jQuery(this) ); return false;">Advanced settings</a> 135 143 136 144 <div id="sb-easy-image-advanced" style="display:none;"> … … 172 180 <label for="<?php echo $this->get_field_id( 'columns' ); ?>"><?php esc_html_e( 'Number of columns to display', 'shellbotics' ); ?></label> 173 181 <input id="<?php echo $this->get_field_id( 'columns' ); ?>" type="text" name="<?php echo $this->get_field_name( 'columns' ); ?>" value="<?php echo $instance['columns']; ?>" class="widefat" /> 182 </p> 183 184 <!-- Filter --> 185 <p> 186 <label for="<?php echo $this->get_field_id( 'filter' ); ?>"><?php esc_html_e('Filter:', 'shellbotics'); ?></label> 187 <select id="<?php echo $this->get_field_id( 'filter' ); ?>" name="<?php echo $this->get_field_name( 'filter' ); ?>" > 188 <?php 189 foreach ( $params['filter'] as $filter ) { 190 ?> 191 <option value="<?php echo $filter; ?>" <?php if ( $filter == $instance['filter'] ) { echo 'selected="selected"'; } ?>> 192 <?php echo $filter; ?> 193 </option> 194 <?php 195 } 196 ?> 197 </select> 198 </p> 199 200 <!-- Image IDs --> 201 <p> 202 <label for="<?php echo $this->get_field_id( 'ids' ); ?>"><?php esc_html_e( 'Image IDs (separate with comma)', 'shellbotics' ); ?></label> 203 <input id="<?php echo $this->get_field_id( 'ids' ); ?>" type="text" name="<?php echo $this->get_field_name( 'ids' ); ?>" value="<?php echo $instance['ids']; ?>" class="widefat" /> 174 204 </p> 175 205 … … 194 224 'link' => $instance['link'], 195 225 'columns' => $instance['columns'], 226 'filter' => $instance['filter'], 227 'ids' => $instance['ids'], 196 228 ); 197 229
Note: See TracChangeset
for help on using the changeset viewer.