Get the Image - Version 0.4

Version Description

Download this release

Release Info

Developer greenshady
Plugin Icon 128x128 Get the Image
Version 0.4
Comparing to
See all releases

Code changes from version 0.3.3 to 0.4

Files changed (4) hide show
  1. get-the-image.php +149 -132
  2. readme.css +11 -0
  3. readme.html +28 -66
  4. readme.txt +14 -5
get-the-image.php CHANGED
@@ -3,16 +3,17 @@
3
  * Plugin Name: Get The Image
4
  * Plugin URI: http://justintadlock.com/archives/2008/05/27/get-the-image-wordpress-plugin
5
  * Description: This is a highly intuitive script that can grab an image by custom field input, post attachment, or extracting it from the post's content.
6
- * Version: 0.3.3
7
  * Author: Justin Tadlock
8
  * Author URI: http://justintadlock.com
9
  *
10
- * Get the Image - A highly-intuitive image script.
11
- * Loads images that are related to the post in some way.
12
- * Offers an image-based representation of WordPress posts.
 
13
  *
14
  * @copyright 2008 - 2009
15
- * @version 0.3.3
16
  * @author Justin Tadlock
17
  * @link http://justintadlock.com/archives/2008/05/27/get-the-image-wordpress-plugin
18
  * @license http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
@@ -24,32 +25,30 @@
24
  * @package GetTheImage
25
  */
26
 
 
 
 
27
  /**
28
- * This is a highly intuitive function that gets images.
29
- * It first calls for custom field keys.
30
- * If no custom field key is set, check for images attached to post.
31
- * Check for image order if looking for attached images.
32
- * Scan the post for images if $image_scan = true.
33
- * Check for default image if $default_image = true.
34
- * If an image is found, call display_the_image() to format it.
35
- *
36
- * Entirely rewrote the system in 0.3.
37
- * Arguments should be in an array (preferably).
38
- *
39
- * In 0.3.3, added the 'get_the_image' filter hook.
40
- *
41
- * @todo Add in the functionality to input a post ID.
42
  *
43
  * @since 0.1
44
- * @param array|string $args Mixed parameters for what image to get
45
- * @return string Image or image with link if one is found
 
46
  */
47
  function get_the_image( $args = array() ) {
 
48
 
 
49
  $defaults = array(
50
  'custom_key' => array( 'Thumbnail', 'thumbnail' ),
51
- 'post_id' => false, // Build functionality in later
52
  'attachment' => true,
 
53
  'default_size' => 'thumbnail',
54
  'default_image' => false,
55
  'order_of_image' => 1,
@@ -62,115 +61,143 @@ function get_the_image( $args = array() ) {
62
  'echo' => true
63
  );
64
 
 
65
  $args = apply_filters( 'get_the_image_args', $args );
66
 
 
67
  $args = wp_parse_args( $args, $defaults );
68
 
 
69
  extract( $args );
70
 
71
- if ( !is_array( $custom_key ) ) :
72
- $custom_key = str_replace( ' ', '', $custom_key) ;
73
- $custom_key = str_replace( array( '+' ), ',', $custom_key );
74
- $custom_key = explode( ',', $custom_key );
75
- $args['custom_key'] = $custom_key;
76
- endif;
77
-
78
- if ( $custom_key && $custom_key !== 'false' && $custom_key !== '0' )
79
  $image = image_by_custom_field( $args );
80
 
81
- if ( !$image && $attachment && $attachment !== 'false' && $attachment !== '0' )
 
 
 
 
 
82
  $image = image_by_attachment( $args );
83
 
 
84
  if ( !$image && $image_scan )
85
  $image = image_by_scan( $args );
86
 
87
- if (!$image && $default_image )
 
88
  $image = image_by_default( $args );
89
 
 
90
  if ( $image )
91
  $image = display_the_image( $args, $image );
92
 
 
93
  $image = apply_filters( 'get_the_image', $image );
94
 
95
- if ( $echo && $echo !== 'false' && $echo !== '0' && $format !== 'array' )
 
96
  echo $image;
97
  else
98
  return $image;
99
  }
100
 
 
 
101
  /**
102
- * Calls images by custom field key
103
- * Script loops through multiple custom field keys
104
- * If that particular key is found, $image is set and the loop breaks
105
- * If an image is found, it is returned
106
  *
107
  * @since 0.3
108
- * @global $post The current post's DB object.
109
  * @param array $args
110
  * @return array|bool
111
  */
112
  function image_by_custom_field( $args = array() ) {
113
 
114
- extract( $args );
115
-
116
- if ( !$post_id )
117
- global $post;
118
 
119
- if ( isset( $custom_key ) ) :
120
- foreach ( $custom_key as $custom ) :
121
- $image = get_post_meta( $post->ID, $custom, true );
122
- if ( $image ) :
 
123
  break;
124
- endif;
125
- endforeach;
126
- if ( !$image ) :
127
- return false;
128
- endif;
129
- endif;
130
-
131
- return array( 'image' => $image );
132
  }
133
 
134
  /**
135
- * Check for attachment images
136
- * Uses get_children() to check if the post has images attached
137
- * If image attachments are found, loop through each
138
- * The loop only breaks once $order_of_image is reached
139
  *
140
- * @since 0.3
141
- * @global $post The current post's DB object.
142
  * @param array $args
143
  * @return array|bool
144
  */
145
- function image_by_attachment( $args = array() ) {
146
 
147
- extract( $args );
 
 
 
 
 
148
 
149
- if ( !$post_id )
150
- global $post;
151
 
152
- /* Get attachments */
153
- $attachments = get_children( array( 'post_parent' => $post->ID, 'post_status' => 'inherit', 'post_type' => 'attachment', 'post_mime_type' => 'image', 'order' => 'ASC', 'orderby' => 'menu_order ID' ) );
154
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
155
  if ( empty( $attachments ) )
156
  return false;
157
 
158
- foreach ( $attachments as $id => $attachment ) :
159
- $i++;
160
- if ( $i == $order_of_image ) :
161
- $image = wp_get_attachment_image_src( $id, $default_size );
162
- $image = $image[0];
163
  break;
164
- endif;
165
- endforeach;
166
 
167
- return array( 'image' => $image );
 
168
  }
169
 
170
  /**
171
- * Scans the post for images within the content
172
- * Not called by default with get_the_image()
173
- * Shouldn't use if using large images within posts, better to use the other options
174
  *
175
  * @since 0.3
176
  * @global $post The current post's DB object.
@@ -179,103 +206,93 @@ function image_by_attachment( $args = array() ) {
179
  */
180
  function image_by_scan( $args = array() ) {
181
 
182
- if ( !$post_id )
183
- global $post;
184
-
185
- preg_match_all( '|<img.*?src=[\'"](.*?)[\'"].*?>|i', $post->post_content, $matches );
186
 
187
- if ( isset( $matches ) ) $image = $matches[1][0];
 
 
188
 
189
- if ( $matches[1][0] )
190
- return array( 'image' => $image );
191
- else
192
- return false;
193
  }
194
 
195
  /**
196
- * Used for setting a default image
197
- * Not used with get_the_image() by default
198
  *
199
  * @since 0.3
200
  * @param array $args
201
  * @return array
202
  */
203
  function image_by_default( $args = array() ) {
204
-
205
- extract( $args );
206
-
207
- $image = $default_image;
208
-
209
- return array( 'image' => $image );
210
  }
211
 
212
  /**
213
- * Formats an image with appropriate alt text and class
214
- * Adds a link to the post if argument is set
215
- * Should only be called if there is an image to display, but will handle it if not
216
  *
217
  * @since 0.1
218
- * @global $post The current post's DB object.
219
  * @param array $args
220
- * @param array $arr Array of image info ($image, $classes, $alt, $caption)
221
- * @return string $image Formatted image (w/link to post if the option is set)
222
  */
223
- function display_the_image( $args = array(), $arr = false ) {
224
- global $post;
225
-
226
- extract( $arr );
227
 
228
- if ( !$image )
229
- return;
 
230
 
 
231
  extract( $args );
232
 
233
- $img = $image;
234
-
235
  if ( $width )
236
  $width = ' width="' . $width . '"';
237
  if ( $height )
238
  $height = ' height="' . $height . '"';
239
 
240
- if ( is_array( $custom_key ) ) :
241
- foreach ( $custom_key as $key ) :
242
- if ( $key !== 'false' && $key !== '0' ) :
243
- $classes[] = str_replace( ' ', '-', strtolower( $key ) );
244
- endif;
245
- endforeach;
246
- endif;
247
 
 
248
  $classes[] = $default_size;
249
  $classes[] = $image_class;
250
 
 
251
  $class = join( ' ', $classes );
252
 
253
- $image = '';
 
 
254
 
255
- if ( $format == 'array' ) :
256
- $image = array(
257
- 'url' => $img,
258
- 'alt' => the_title_attribute( 'echo=0' ),
259
- 'class' => $class,
260
- 'link' => get_permalink( $post->ID ),
261
- );
262
- return $image;
263
- endif;
264
 
 
 
 
 
265
  if ( $link_to_post )
266
- $image .= '<a href="' . get_permalink( $post->ID ) . '" title="' . the_title_attribute( 'echo=0' ) . '">';
267
 
268
- $image .= '<img src="' . $img . '" alt="' . the_title_attribute( 'echo=0' ) . '" class="' . $class . '"' . $width . $height . ' />';
 
 
269
 
270
- if ( $link_to_post )
271
- $image .= '</a>';
 
272
 
273
- return $image;
274
  }
275
 
276
  /**
277
- * Get the image with a link to the post
278
- * Use get_the_image() instead
279
  *
280
  * @since 0.1
281
  * @deprecated 0.3
3
  * Plugin Name: Get The Image
4
  * Plugin URI: http://justintadlock.com/archives/2008/05/27/get-the-image-wordpress-plugin
5
  * Description: This is a highly intuitive script that can grab an image by custom field input, post attachment, or extracting it from the post's content.
6
+ * Version: 0.4
7
  * Author: Justin Tadlock
8
  * Author URI: http://justintadlock.com
9
  *
10
+ * Get the Image was created to solve a problem in the WordPress community about how to handle
11
+ * post-specific images. It was created to be a highly-intuitive image script that loads images that are
12
+ * related to specific posts in some way. It creates an image-based representation of a WordPress
13
+ * post (or any post type).
14
  *
15
  * @copyright 2008 - 2009
16
+ * @version 0.4
17
  * @author Justin Tadlock
18
  * @link http://justintadlock.com/archives/2008/05/27/get-the-image-wordpress-plugin
19
  * @license http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
25
  * @package GetTheImage
26
  */
27
 
28
+ /* Adds theme support for post images. */
29
+ add_theme_support( 'post-thumbnails' );
30
+
31
  /**
32
+ * This is a highly intuitive function that gets images. It first calls for custom field keys. If no
33
+ * custom field key is set, check for the_post_thumbnail(). If no post image, check for images
34
+ * attached to post. Check for image order if looking for attached images. Scan the post for
35
+ * images if $image_scan = true. Check for default image if $default_image = true. If an image
36
+ * is found, call display_the_image() to format it.
 
 
 
 
 
 
 
 
 
37
  *
38
  * @since 0.1
39
+ * @global $post The current post's DB object.
40
+ * @param array $args Parameters for what image to get.
41
+ * @return string|array The HTML for the image. | Image attributes in an array.
42
  */
43
  function get_the_image( $args = array() ) {
44
+ global $post;
45
 
46
+ /* Set the default arguments. */
47
  $defaults = array(
48
  'custom_key' => array( 'Thumbnail', 'thumbnail' ),
49
+ 'post_id' => $post->ID,
50
  'attachment' => true,
51
+ 'the_post_thumbnail' => true, // WP 2.9+ image function
52
  'default_size' => 'thumbnail',
53
  'default_image' => false,
54
  'order_of_image' => 1,
61
  'echo' => true
62
  );
63
 
64
+ /* Allow plugins/themes to filter the arguments. */
65
  $args = apply_filters( 'get_the_image_args', $args );
66
 
67
+ /* Merge the input arguments and the defaults. */
68
  $args = wp_parse_args( $args, $defaults );
69
 
70
+ /* Extract the array to allow easy use of variables. */
71
  extract( $args );
72
 
73
+ /* If a custom field key (array) is defined, check for images by custom field. */
74
+ if ( $custom_key )
 
 
 
 
 
 
75
  $image = image_by_custom_field( $args );
76
 
77
+ /* If no image found and $the_post_thumbnail is set to true, check for a post image (WP feature). */
78
+ if ( !$image && $the_post_thumbnail )
79
+ $image = image_by_the_post_thumbnail( $args );
80
+
81
+ /* If no image found and $attachment is set to true, check for an image by attachment. */
82
+ if ( !$image && $attachment )
83
  $image = image_by_attachment( $args );
84
 
85
+ /* If no image found and $image_scan is set to true, scan the post for images. */
86
  if ( !$image && $image_scan )
87
  $image = image_by_scan( $args );
88
 
89
+ /* If no image found and a $default_image is set, get the default image. */
90
+ if ( !$image && $default_image )
91
  $image = image_by_default( $args );
92
 
93
+ /* If an image is returned, run it through the display function. */
94
  if ( $image )
95
  $image = display_the_image( $args, $image );
96
 
97
+ /* Allow plugins/theme to override the final output. */
98
  $image = apply_filters( 'get_the_image', $image );
99
 
100
+ /* Display the image if $echo is set to true and the $format isn't an array. Else, return the image. */
101
+ if ( $echo && 'array' !== $format )
102
  echo $image;
103
  else
104
  return $image;
105
  }
106
 
107
+ /* Internal Functions */
108
+
109
  /**
110
+ * Calls images by custom field key. Script loops through multiple custom field keys.
111
+ * If that particular key is found, $image is set and the loop breaks. If an image is
112
+ * found, it is returned.
 
113
  *
114
  * @since 0.3
 
115
  * @param array $args
116
  * @return array|bool
117
  */
118
  function image_by_custom_field( $args = array() ) {
119
 
120
+ /* If $custom_key is a string, we want to split it by spaces into an array. */
121
+ if ( !is_array( $args['custom_key'] ) )
122
+ $args['custom_key'] = preg_split( '#\s+#', $args['custom_key'] );
 
123
 
124
+ /* If $custom_key is set, loop through each custom field key, searching for values. */
125
+ if ( isset( $args['custom_key'] ) ) {
126
+ foreach ( $args['custom_key'] as $custom ) {
127
+ $image = get_metadata( 'post', $args['post_id'], $custom, true );
128
+ if ( $image )
129
  break;
130
+ }
131
+ }
132
+
133
+ /* If a custom key value has been given for one of the keys, return the image URL. */
134
+ if ( $image )
135
+ return array( 'url' => $image );
136
+
137
+ return false;
138
  }
139
 
140
  /**
141
+ * Checks for images using a custom version of the WordPress 2.9+ get_the_post_thumbnail()
142
+ * function. If an image is found, return it and the $post_thumbnail_id. The WordPress function's
143
+ * other filters are later added in the display_the_image() function.
 
144
  *
145
+ * @since 0.4
 
146
  * @param array $args
147
  * @return array|bool
148
  */
149
+ function image_by_the_post_thumbnail( $args = array() ) {
150
 
151
+ /* Check for a post image ID (set by WP as a custom field). */
152
+ $post_thumbnail_id = get_post_thumbnail_id( $args['post_id'] );
153
+
154
+ /* If no post image ID is found, return false. */
155
+ if ( empty( $post_thumbnail_id ) )
156
+ return false;
157
 
158
+ /* Apply filters on post_thumbnail_size because this is a default WP filter used with its image feature. */
159
+ $size = apply_filters( 'post_thumbnail_size', $args['default_size'] );
160
 
161
+ /* Get the attachment image source. This should return an array. */
162
+ $image = wp_get_attachment_image_src( $post_thumbnail_id, $size );
163
 
164
+ /* Return both the image URL and the post thumbnail ID. */
165
+ return array( 'url' => $image[0], 'post_thumbnail_id' => $post_thumbnail_id );
166
+ }
167
+
168
+ /**
169
+ * Check for attachment images. Uses get_children() to check if the post has images
170
+ * attached. If image attachments are found, loop through each. The loop only breaks
171
+ * once $order_of_image is reached.
172
+ *
173
+ * @since 0.3
174
+ * @param array $args
175
+ * @return array|bool
176
+ */
177
+ function image_by_attachment( $args = array() ) {
178
+
179
+ /* Get attachments for the inputted $post_id. */
180
+ $attachments = get_children( array( 'post_parent' => $args['post_id'], 'post_status' => 'inherit', 'post_type' => 'attachment', 'post_mime_type' => 'image', 'order' => 'ASC', 'orderby' => 'menu_order ID' ) );
181
+
182
+ /* If no attachments are found, return false. */
183
  if ( empty( $attachments ) )
184
  return false;
185
 
186
+ /* Loop through each attachment. Once the $order_of_image (default is '1') is reached, break the loop. */
187
+ foreach ( $attachments as $id => $attachment ) {
188
+ if ( ++$i == $args['order_of_image'] ) {
189
+ $image = wp_get_attachment_image_src( $id, $args['default_size'] );
 
190
  break;
191
+ }
192
+ }
193
 
194
+ /* Return the image URL. */
195
+ return array( 'url' => $image[0] );
196
  }
197
 
198
  /**
199
+ * Scans the post for images within the content. Not called by default with get_the_image().
200
+ * Shouldn't use if using large images within posts, better to use the other options.
 
201
  *
202
  * @since 0.3
203
  * @global $post The current post's DB object.
206
  */
207
  function image_by_scan( $args = array() ) {
208
 
209
+ /* Search the post's content for the <img /> tag and get its URL. */
210
+ preg_match_all( '|<img.*?src=[\'"](.*?)[\'"].*?>|i', get_post_field( 'post_content', $args['post_id'] ), $matches );
 
 
211
 
212
+ /* If there is a match for the image, return its URL. */
213
+ if ( isset( $matches ) && $matches[1][0] )
214
+ return array( 'url' => $matches[1][0] );
215
 
216
+ return false;
 
 
 
217
  }
218
 
219
  /**
220
+ * Used for setting a default image. The function simply returns the image URL it was
221
+ * given in an array. Not used with get_the_image() by default.
222
  *
223
  * @since 0.3
224
  * @param array $args
225
  * @return array
226
  */
227
  function image_by_default( $args = array() ) {
228
+ return array( 'url' => $args['default_image'] );
 
 
 
 
 
229
  }
230
 
231
  /**
232
+ * Formats an image with appropriate alt text and class. Adds a link to the post if argument
233
+ * is set. Should only be called if there is an image to display, but will handle it if not.
 
234
  *
235
  * @since 0.1
 
236
  * @param array $args
237
+ * @param array $image Array of image info ($image, $classes, $alt, $caption).
238
+ * @return string $image Formatted image (w/link to post if the option is set).
239
  */
240
+ function display_the_image( $args = array(), $image = false ) {
 
 
 
241
 
242
+ /* If there is no image URL, return false. */
243
+ if ( empty( $image['url'] ) )
244
+ return false;
245
 
246
+ /* Extract the arguments for easy-to-use variables. */
247
  extract( $args );
248
 
249
+ /* If there is a width or height, set them as HMTL-ready attributes. */
 
250
  if ( $width )
251
  $width = ' width="' . $width . '"';
252
  if ( $height )
253
  $height = ' height="' . $height . '"';
254
 
255
+ /* Loop through the custom field keys and add them as classes. */
256
+ if ( is_array( $custom_key ) ) {
257
+ foreach ( $custom_key as $key )
258
+ $classes[] = str_replace( ' ', '-', strtolower( $key ) );
259
+ }
 
 
260
 
261
+ /* Add the $default_size and any user-added $image_class to the class. */
262
  $classes[] = $default_size;
263
  $classes[] = $image_class;
264
 
265
+ /* Join all the classes into a single string. */
266
  $class = join( ' ', $classes );
267
 
268
+ /* If $format should be an array, return the attributes in array format. */
269
+ if ( 'array' == $format )
270
+ return array( 'url' => $image['url'], 'alt' => esc_attr( strip_tags( get_post_field( 'post_title', $post_id ) ) ), 'class' => $class, 'link' => get_permalink( $post_id ) );
271
 
272
+ /* If there is a $post_thumbnail_id, apply the WP filters normally associated with get_the_post_thumbnail(). */
273
+ if ( $image['post_thumbnail_id'] )
274
+ do_action( 'begin_fetch_post_thumbnail_html', $post_id, $image['post_thumbnail_id'], $default_size );
 
 
 
 
 
 
275
 
276
+ /* Add the image attributes to the <img /> element. */
277
+ $html = '<img src="' . $image['url'] . '" alt="' . esc_attr( strip_tags( get_post_field( 'post_title', $post_id ) ) ) . '" class="' . $class . '"' . $width . $height . ' />';
278
+
279
+ /* If $link_to_post is set to true, link the image to its post. */
280
  if ( $link_to_post )
281
+ $html = '<a href="' . get_permalink( $post_id ) . '" title="' . esc_attr( get_post_field( 'post_title', $post_id ) ) . '">' . $html . '</a>';
282
 
283
+ /* If there is a $post_thumbnail_id, apply the WP filters normally associated with get_the_post_thumbnail(). */
284
+ if ( $image['post_thumbnail_id'] )
285
+ do_action( 'end_fetch_post_thumbnail_html', $post_id, $image['post_thumbnail_id'], $default_size );
286
 
287
+ /* If there is a $post_thumbnail_id, apply the WP filters normally associated with get_the_post_thumbnail(). */
288
+ if ( $image['post_thumbnail_id'] )
289
+ $html = apply_filters( 'post_thumbnail_html', $html, $post_id, $image['post_thumbnail_id'], $default_size, $attr );
290
 
291
+ return $html;
292
  }
293
 
294
  /**
295
+ * Get the image with a link to the post. Use get_the_image() instead.
 
296
  *
297
  * @since 0.1
298
  * @deprecated 0.3
readme.css CHANGED
@@ -22,6 +22,11 @@ h1, h2, h3, h4, h5, h6 {
22
  font-weight: bold;
23
  font-family: Arial, sans-serif;
24
  }
 
 
 
 
 
25
  h1 {
26
  margin-top: 80px;
27
  font-size: 2.2em;
@@ -63,4 +68,10 @@ ul.space li {
63
  float: left;
64
  width: 230px;
65
  margin: 0 0 21px 20px;
 
 
 
 
 
 
66
  }
22
  font-weight: bold;
23
  font-family: Arial, sans-serif;
24
  }
25
+ h3 {
26
+ font-weight: normal;
27
+ font-style: italic;
28
+ font-family: Georgia, Times, 'Times New Roman', serif;
29
+ }
30
  h1 {
31
  margin-top: 80px;
32
  font-size: 2.2em;
68
  float: left;
69
  width: 230px;
70
  margin: 0 0 21px 20px;
71
+ }
72
+ /* Warnings/Alerts */
73
+ .warning, .alert {
74
+ padding: 6px 9px;
75
+ background: #fffbbc;
76
+ border: 1px solid #E6DB55;
77
  }
readme.html CHANGED
@@ -9,15 +9,11 @@
9
  </head>
10
  <body>
11
 
12
- <h1 title="A guide to using the Get the Image plugin">A guide to Get the Image</h1>
13
 
14
- <p>
15
- <em>Get the Image</em> is a plugin that grabs images for you. It was designed to make the process of things such as adding thumbnails, feature images, and/or other images to your blog much easier, but it's so much more than that. It is an image-based representation of your WordPress posts.
16
- </p>
17
 
18
- <p>
19
- To use this plugin, you must be familiar with two very important things in WordPress: the <a href="http://codex.wordpress.org/Template_Hierarchy" title="Template Hierarchy">Template Hierarchy</a> and <a href="http://codex.wordpress.org/The_Loop" title="The Loop">The Loop</a>. If you don't have a working knowledge of those two things, then you should not attempt to use this plugin. More importantly, you should be familiar with how all of this works within your theme because not all themes are the same.
20
- </p>
21
 
22
  <h2>What this plugin does</h2>
23
 
@@ -25,6 +21,7 @@ To use this plugin, you must be familiar with two very important things in WordP
25
 
26
  <ol>
27
  <li>Looks for an image by custom field.</li>
 
28
  <li>If no image is found, it grabs an image attached to your post.</li>
29
  <li>If no image is attached, it can extract an image from your post content (off by default).</li>
30
  <li>If no image is found at this point, it will default to an image you set (not set by default).</li>
@@ -33,44 +30,31 @@ To use this plugin, you must be familiar with two very important things in WordP
33
  <h2>How to install the plugin</h2>
34
 
35
  <ol>
36
- <li>Uzip the <code>get-the-image.zip</code> folder.</li>
37
- <li>Upload the <code>get-the-image</code> folder to your <code>/wp-content/plugins</code> directory.</li>
38
- <li>In your WordPress dashboard, head over to the <em>Plugins</em> section.</li>
39
- <li>Activate <em>Get The Image</em>.</li>
40
  </ol>
41
 
42
- <p>
43
- <strong>If you are upgrading from a version prior to 0.3</strong> just overwrite your old files. You'll need to change the calls to the plugin in your template files though because how the plugin works has changed. Follow the instructions below to see how the image script should be called.
44
- </p>
45
 
46
  <h2>How to use the plugin</h2>
47
 
48
- <p>
49
- First, you should know that there are two types of ways to call the image script, either with <a href="http://codex.wordpress.org/Template_Tags/How_to_Pass_Tag_Parameters#Tags_with_PHP_function-style_parameters" title="PHP function-style parameters">function-style parameters</a> or <a href="http://codex.wordpress.org/Template_Tags/How_to_Pass_Tag_Parameters#Tags_with_query-string-style_parameters" title="Query-string-style parameters">query-string-style parameters</a>. I prefer the former over the latter because it simply works better and is the way I'll be explaining throughout this guide.
50
- </p>
51
 
52
- <p>
53
- <strong>Example with function-style parameters</strong>
54
- </p>
55
 
56
  <pre><code>&lt;?php get_the_image( array( 'custom_key' => array( 'Thumbnail', 'thumbnail' ), 'default_size' => 'thumbnail' ) ); ?></code></pre>
57
 
58
- <p>
59
- <strong>Example with query-string-style parameters</strong>
60
- </p>
61
-
62
- <pre><code>&lt;?php get_the_image( 'custom_key=Thumbnail,thumbnail&amp;default_size=thumbnail' ); ?></code></pre>
63
-
64
  <h2>The image script parameters</h2>
65
 
66
- <p>
67
- By simply making a function call to <code>&lt;?php get_the_image(); ?></code> within a template file, the script will default to this:
68
- </p>
69
 
70
  <pre><code>$defaults = array(
71
  'custom_key' => array( 'Thumbnail', 'thumbnail' ),
72
  'attachment' => true,
73
  'default_size' => 'thumbnail',
 
74
  'default_image' => false,
75
  'order_of_image' => 1,
76
  'link_to_post' => true,
@@ -88,6 +72,8 @@ By simply making a function call to <code>&lt;?php get_the_image(); ?></code> wi
88
  <dd>The script will look for images attached to the post (set to <code>true</code> by default).</dd>
89
  <dt>default_size</dt>
90
  <dd>This refers to the default size of an attached image. You can choose between <code>thumbnail</code>, <code>medium</code>, <code>large</code> (WP 2.7+), or <code>full</code> (the default is <code>thumbnail</code>).</dd>
 
 
91
  <dt>default_image</dt>
92
  <dd>Will take the input of an image URL and use it if no other images are found (no default set).</dd>
93
  <dt>order_of_image</dt>
@@ -108,51 +94,37 @@ By simply making a function call to <code>&lt;?php get_the_image(); ?></code> wi
108
 
109
  <h2>Some examples of how to use this plugin</h2>
110
 
111
- <p>
112
- <strong>Example 1:</strong> Let's suppose that you want to add thumbnails to your category archive pages. What you'll need to do is open your <code>category.php</code> file and add this code within the Loop:
113
- </p>
114
 
115
  <pre><code>&lt;?php get_the_image(); ?></code></pre>
116
 
117
- <p>
118
- By default, that will look for an image with the custom field <strong>key</strong> <code>Thumbnail</code> and <code>thumnbail</code>. If that image doesn't exist, it will search for any images attached to your post.
119
- </p>
120
 
121
- <p>
122
- <strong>Example 2:</strong> Let's suppose you want a full-sized image and maybe you want to grab it by a custom field key of <code>Feature</code>. Depending on your theme, this will need to go within the Loop in whatever file is calling the featured article.
123
- </p>
124
 
125
  <pre><code>&lt;?php get_the_image( array( 'custom_key' => array( 'Feature' ), 'default_size' => 'full' ) ); ?></code></pre>
126
 
127
  <p>If no feature image exists by custom field, it will look for images attached to your post.</p>
128
 
129
- <p>
130
- <strong>Example 3:</strong> If you want to have a sort of fallback image, then you can set an image for the script to default to if no other images are found.
131
- </p>
132
 
133
  <pre><code>&lt;?php get_the_image( array( 'default_image' => 'http://mysite.com/wp-content/uploads/example.jpg' ) ); ?></code></pre>
134
 
135
- <p>
136
- <strong>Example 4:</strong> You can even make the script scan for images that have been added to your post with this:
137
- </p>
138
 
139
  <pre><code>&lt;?php get_the_image( array( 'image_scan' => true ) ); ?></code></pre>
140
 
141
- <p>
142
- <strong>Example 5:</strong> You might want to make the script grab the second attached image to a post. You can do that with this code:
143
- </p>
144
 
145
  <pre><code>&lt;?php get_the_image( array( 'order_of_image' => 2 ) ); ?></code></pre>
146
 
147
  <h2>A real-world example</h2>
148
 
149
- <p>
150
- This is an example Loop, which may differ slightly from your theme, but the concept is the same. The call to get the image can go anywhere between the opening and closing lines.
151
- </p>
152
 
153
  <pre><code>&lt;?php if ( have_posts() ) : while ( have_posts() ) : the_post(); ?>
154
 
155
- &lt;div class="hentry">
156
 
157
  &lt;?php get_the_image( array( 'custom_key' => array( 'feature_img' ), 'default_size' => 'medium', 'width' => '200', 'height' => '200', 'image_class' => 'feature' ) ); ?>
158
 
@@ -166,27 +138,17 @@ This is an example Loop, which may differ slightly from your theme, but the conc
166
 
167
  &lt;?php endwhile; endif; ?></code></pre>
168
 
169
- <p>Alternately, you could use the query-string-style format to call the image like so:</p>
170
-
171
- <pre><code>&lt;?php get_the_image( 'custom_key=feature_image&amp;default_size=medium&amp;width=200&amp;height=200&amp;image_class=feature' ); ?></code></pre>
172
-
173
  <h2>Protect yourself from errors in the future</h2>
174
 
175
- <p>
176
- Sometimes, we stop using plugins, but we forget to remove the function calls to the plugin in our theme files. When deactivated, this causes errors. To protect yourself from these errors, you can call the image script like this:
177
- </p>
178
 
179
  <pre><code>&lt;?php if ( function_exists( 'get_the_image' ) ) { get_the_image(); } ?></code></pre>
180
 
181
- <p>
182
- Basically, this just checks to see if the plugin is activated and has loaded the appropriate function.
183
- </p>
184
 
185
  <h2>Styling your images</h2>
186
 
187
- <p>
188
- The plugin will help you style your images by giving you some CSS classes to work with. It will turn your custom field keys and default size into CSS classes. You can also choose to input your own class.
189
- </p>
190
 
191
  <p>By default, you can add this to your CSS:</p>
192
 
@@ -219,11 +181,11 @@ img.thumbnail { }</code></pre>
219
 
220
  <h2>Copyright &amp; license</h2>
221
 
222
- <p><em>Get the Image</em> is licensed under the <a href="http://www.gnu.org/licenses/old-licenses/gpl-2.0.html" title="GNU GPL">GNU General Public License</a>, version 2 (GPL).</p>
223
 
224
  <p>This plugin is copyrighted to <a href="http://justintadlock.com" title="Justin Tadlock">Justin Tadlock</a>.</p>
225
 
226
- <p>2008 - 2009 &copy; Justin Tadlock</p>
227
 
228
  </body>
229
  </html>
9
  </head>
10
  <body>
11
 
12
+ <h1>A guide to Get the Image</h1>
13
 
14
+ <p class="first"><em>Get the Image</em> is a plugin that grabs images for you. It was designed to make the process of things such as adding thumbnails, feature images, and/or other images to your blog much easier, but it's so much more than that. It is an image-based representation of your WordPress posts.</p>
 
 
15
 
16
+ <p class="second">To use this plugin, you must be familiar with two very important things in WordPress: the <a href="http://codex.wordpress.org/Template_Hierarchy" title="Template Hierarchy">Template Hierarchy</a> and <a href="http://codex.wordpress.org/The_Loop" title="The Loop">The Loop</a>. If you don't have a working knowledge of those two things, then you should not attempt to use this plugin. More importantly, you should be familiar with how all of this works within your theme because not all themes are the same.</p>
 
 
17
 
18
  <h2>What this plugin does</h2>
19
 
21
 
22
  <ol>
23
  <li>Looks for an image by custom field.</li>
24
+ <li>If no image is added by custom field, check for a <a href="http://justintadlock.com/archives/2009/11/16/everything-you-need-to-know-about-wordpress-2-9s-post-image-feature" title="WordPress 2.9's post image feature">post image</a> (WordPresss 2.9+ feature).</li>
25
  <li>If no image is found, it grabs an image attached to your post.</li>
26
  <li>If no image is attached, it can extract an image from your post content (off by default).</li>
27
  <li>If no image is found at this point, it will default to an image you set (not set by default).</li>
30
  <h2>How to install the plugin</h2>
31
 
32
  <ol>
33
+ <li>Uzip the <code>get-the-image.zip</code> folder.</li>
34
+ <li>Upload the <code>get-the-image</code> folder to your <code>/wp-content/plugins</code> directory.</li>
35
+ <li>In your WordPress dashboard, head over to the <em>Plugins</em> section.</li>
36
+ <li>Activate <em>Get The Image</em>.</li>
37
  </ol>
38
 
39
+ <p class="alert">If you are upgrading from a version prior to 0.3 just overwrite your old files. You'll need to change the calls to the plugin in your template files because how the plugin works has changed. Follow the instructions below to see how the image script should be called.</p>
 
 
40
 
41
  <h2>How to use the plugin</h2>
42
 
43
+ <p>To call the image script, you'll need to use what's called <a href="http://codex.wordpress.org/Template_Tags/How_to_Pass_Tag_Parameters#Tags_with_PHP_function-style_parameters" title="PHP function-style parameters">function-style parameters</a>.</p>
 
 
44
 
45
+ <p><strong>Example with function-style parameters</strong></p>
 
 
46
 
47
  <pre><code>&lt;?php get_the_image( array( 'custom_key' => array( 'Thumbnail', 'thumbnail' ), 'default_size' => 'thumbnail' ) ); ?></code></pre>
48
 
 
 
 
 
 
 
49
  <h2>The image script parameters</h2>
50
 
51
+ <p>By simply making a function call to <code>&lt;?php get_the_image(); ?></code> within a template file, the script will default to this:</p>
 
 
52
 
53
  <pre><code>$defaults = array(
54
  'custom_key' => array( 'Thumbnail', 'thumbnail' ),
55
  'attachment' => true,
56
  'default_size' => 'thumbnail',
57
+ 'the_post_thumbnail' => true,
58
  'default_image' => false,
59
  'order_of_image' => 1,
60
  'link_to_post' => true,
72
  <dd>The script will look for images attached to the post (set to <code>true</code> by default).</dd>
73
  <dt>default_size</dt>
74
  <dd>This refers to the default size of an attached image. You can choose between <code>thumbnail</code>, <code>medium</code>, <code>large</code> (WP 2.7+), or <code>full</code> (the default is <code>thumbnail</code>).</dd>
75
+ <dt>the_post_thumbnail</dt>
76
+ <dd>This refers to the WordPress 2.9's new <code>the_post_thumbnail()</code> feature. By having this set to <code>true</code>, you may select an image from the post image meta box while in the post editor.
77
  <dt>default_image</dt>
78
  <dd>Will take the input of an image URL and use it if no other images are found (no default set).</dd>
79
  <dt>order_of_image</dt>
94
 
95
  <h2>Some examples of how to use this plugin</h2>
96
 
97
+ <p><strong>Example 1:</strong> Let's suppose that you want to add thumbnails to your category archive pages. What you'll need to do is open your <code>category.php</code> file and add this code within the Loop:</p>
 
 
98
 
99
  <pre><code>&lt;?php get_the_image(); ?></code></pre>
100
 
101
+ <p>By default, that will look for an image with the custom field <strong>key</strong> <code>Thumbnail</code> and <code>thumnbail</code>. If that image doesn't exist, it will check if a post image has been set. If that image doesn't exist, it will search for any images attached to your post.</p>
 
 
102
 
103
+ <p><strong>Example 2:</strong> Let's suppose you want a full-sized image and maybe you want to grab it by a custom field key of <code>Feature</code>. Depending on your theme, this will need to go within the Loop in whatever file is calling the featured article.</p>
 
 
104
 
105
  <pre><code>&lt;?php get_the_image( array( 'custom_key' => array( 'Feature' ), 'default_size' => 'full' ) ); ?></code></pre>
106
 
107
  <p>If no feature image exists by custom field, it will look for images attached to your post.</p>
108
 
109
+ <p><strong>Example 3:</strong> If you want to have a sort of fallback image, then you can set an image for the script to default to if no other images are found.</p>
 
 
110
 
111
  <pre><code>&lt;?php get_the_image( array( 'default_image' => 'http://mysite.com/wp-content/uploads/example.jpg' ) ); ?></code></pre>
112
 
113
+ <p><strong>Example 4:</strong> You can even make the script scan for images that have been added to your post with this:</p>
 
 
114
 
115
  <pre><code>&lt;?php get_the_image( array( 'image_scan' => true ) ); ?></code></pre>
116
 
117
+ <p><strong>Example 5:</strong> You might want to make the script grab the second attached image to a post. You can do that with this code:</p>
 
 
118
 
119
  <pre><code>&lt;?php get_the_image( array( 'order_of_image' => 2 ) ); ?></code></pre>
120
 
121
  <h2>A real-world example</h2>
122
 
123
+ <p>This is an example Loop, which may differ slightly from your theme, but the concept is the same. The call to get the image can go anywhere between the opening and closing lines.</p>
 
 
124
 
125
  <pre><code>&lt;?php if ( have_posts() ) : while ( have_posts() ) : the_post(); ?>
126
 
127
+ &lt;div id="post-&lt;?php the_ID(); ?>" &lt;?php post_class(); ?>>
128
 
129
  &lt;?php get_the_image( array( 'custom_key' => array( 'feature_img' ), 'default_size' => 'medium', 'width' => '200', 'height' => '200', 'image_class' => 'feature' ) ); ?>
130
 
138
 
139
  &lt;?php endwhile; endif; ?></code></pre>
140
 
 
 
 
 
141
  <h2>Protect yourself from errors in the future</h2>
142
 
143
+ <p>Sometimes, we stop using plugins, but we forget to remove the function calls to the plugin in our theme files. When deactivated, this causes errors. To protect yourself from these errors, you can call the image script like this:</p>
 
 
144
 
145
  <pre><code>&lt;?php if ( function_exists( 'get_the_image' ) ) { get_the_image(); } ?></code></pre>
146
 
147
+ <p>Basically, this just checks to see if the plugin is activated and has loaded the appropriate function.</p>
 
 
148
 
149
  <h2>Styling your images</h2>
150
 
151
+ <p>The plugin will help you style your images by giving you some CSS classes to work with. It will turn your custom field keys and default size into CSS classes. You can also choose to input your own class.</p>
 
 
152
 
153
  <p>By default, you can add this to your CSS:</p>
154
 
181
 
182
  <h2>Copyright &amp; license</h2>
183
 
184
+ <p><em>Get the Image</em> is licensed under the <a href="http://www.gnu.org/licenses/old-licenses/gpl-2.0.html" title="GNU GPL">GNU General Public License</a>, version 2 (<acronym title="GNU General Public License">GPL</acronym>).</p>
185
 
186
  <p>This plugin is copyrighted to <a href="http://justintadlock.com" title="Justin Tadlock">Justin Tadlock</a>.</p>
187
 
188
+ <p>2008&thinsp;&ndash;&thinsp;2009 &copy; Justin Tadlock. All rights reserved.</p>
189
 
190
  </body>
191
  </html>
readme.txt CHANGED
@@ -2,9 +2,9 @@
2
  Contributors: greenshady
3
  Donate link: https://www.paypal.com/cgi-bin/webscr?cmd=_s-xclick&hosted_button_id=3687060
4
  Tags: image, images, thumbnail
5
- Requires at least: 2.5
6
- Tested up to: 2.8
7
- Stable tag: 0.3.3
8
 
9
  An easy-to-use image script for adding things such as thumbnails and feature images.
10
 
@@ -12,7 +12,7 @@ An easy-to-use image script for adding things such as thumbnails and feature ima
12
 
13
  *Get the Image* is a plugin that grabs images for you. It was designed to make the process of things such as adding thumbnails, feature images, and/or other images to your blog much easier, but it's so much more than that. It is an image-based representation of your WordPress posts.
14
 
15
- This is a highly intuitive script that can grab an image by custom field input, post attachment, or extracting it from the post's content.
16
 
17
  == Installation ==
18
 
@@ -35,6 +35,7 @@ This plugin was created to be a lightweight solution to handle a very powerful n
35
  = How does it pull images? =
36
 
37
  1. Looks for an image by custom field (one of your choosing).
 
38
  1. If no image is found, it grabs an image attached to your post.
39
  1. If no image is attached, it can extract an image from your post content (off by default).
40
  1. If no image is found at this point, it will default to an image you set (not set by default).
@@ -55,7 +56,15 @@ You can view this plugin in action on my <a href="http://justintadlock.com" titl
55
 
56
  == Changelog ==
57
 
58
- Ealier versions were not documented well.
 
 
 
 
 
 
 
 
59
 
60
  **Version 0.3.3**
61
 
2
  Contributors: greenshady
3
  Donate link: https://www.paypal.com/cgi-bin/webscr?cmd=_s-xclick&hosted_button_id=3687060
4
  Tags: image, images, thumbnail
5
+ Requires at least: 2.9
6
+ Tested up to: 2.9
7
+ Stable tag: 0.4
8
 
9
  An easy-to-use image script for adding things such as thumbnails and feature images.
10
 
12
 
13
  *Get the Image* is a plugin that grabs images for you. It was designed to make the process of things such as adding thumbnails, feature images, and/or other images to your blog much easier, but it's so much more than that. It is an image-based representation of your WordPress posts.
14
 
15
+ This is a highly intuitive script that can grab an image by custom field input, WP's post image feature, post attachment, or extracting it from the post's content.
16
 
17
  == Installation ==
18
 
35
  = How does it pull images? =
36
 
37
  1. Looks for an image by custom field (one of your choosing).
38
+ 1. If no image is added by custom field, check for an image using `the_post_thumbnail()` (WP 2.9's new image feature).
39
  1. If no image is found, it grabs an image attached to your post.
40
  1. If no image is attached, it can extract an image from your post content (off by default).
41
  1. If no image is found at this point, it will default to an image you set (not set by default).
56
 
57
  == Changelog ==
58
 
59
+ Earlier versions were not documented well.
60
+
61
+ **Version 0.4**
62
+
63
+ * Dropped support for older versions of WordPress. Now only compatible with 2.9+.
64
+ * Added support for `the_post_thumbnail()`, which is WordPress 2.9's new image functionality.
65
+ * New function: `image_by_the_post_thumbnail()`.
66
+ * Documented more of the code, so the inline PHP doc is updated.
67
+ * Cleaned up some of the old legacy code that's no longer needed.
68
 
69
  **Version 0.3.3**
70