Version Description
Download this release
Release Info
Developer | greenshady |
Plugin | Get the Image |
Version | 0.3.1 |
Comparing to | |
See all releases |
Version 0.3.1
- get-the-image.php +265 -0
- readme.css +280 -0
- readme.html +229 -0
- readme.txt +69 -0
get-the-image.php
ADDED
@@ -0,0 +1,265 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
/*
|
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.1
|
7 |
+
Author: Justin Tadlock
|
8 |
+
Author URI: http://justintadlock.com
|
9 |
+
License: GPL
|
10 |
+
*/
|
11 |
+
|
12 |
+
/**
|
13 |
+
* This is a highly intuitive script file that gets images
|
14 |
+
* It first calls for custom field keys
|
15 |
+
* If no custom field key is set, check for images "attached" to post
|
16 |
+
* Check for image order if looking for attached images
|
17 |
+
* Scan the post for images if $image_scan = true
|
18 |
+
* Check for default image if $default_image = true
|
19 |
+
*
|
20 |
+
* Entirely rewrote the system in 0.4
|
21 |
+
*
|
22 |
+
* @package Hybrid
|
23 |
+
* @subpackage Media
|
24 |
+
*
|
25 |
+
* @since 0.1
|
26 |
+
* @filter get_the_image_args
|
27 |
+
*/
|
28 |
+
function get_the_image($args = array()) {
|
29 |
+
|
30 |
+
$defaults = array(
|
31 |
+
'custom_key' => array('Thumbnail','thumbnail'),
|
32 |
+
'post_id' => false, // Build functionality in later
|
33 |
+
'attachment' => true,
|
34 |
+
'default_size' => 'thumbnail',
|
35 |
+
'default_image' => false,
|
36 |
+
'order_of_image' => 1,
|
37 |
+
'link_to_post' => true,
|
38 |
+
'image_class' => false,
|
39 |
+
'image_scan' => false,
|
40 |
+
'width' => false,
|
41 |
+
'height' => false,
|
42 |
+
'format' => 'img',
|
43 |
+
'echo' => true
|
44 |
+
);
|
45 |
+
|
46 |
+
$args = apply_filters('get_the_image_args', $args);
|
47 |
+
|
48 |
+
$args = wp_parse_args($args, $defaults);
|
49 |
+
|
50 |
+
extract($args);
|
51 |
+
|
52 |
+
if(!is_array($custom_key)) :
|
53 |
+
$custom_key = str_replace(' ', '', $custom_key);
|
54 |
+
$custom_key = str_replace(array('+'), ',', $custom_key);
|
55 |
+
$custom_key = explode(',', $custom_key);
|
56 |
+
$args['custom_key'] = $custom_key;
|
57 |
+
endif;
|
58 |
+
|
59 |
+
if($custom_key && $custom_key !== 'false' && $custom_key !== '0') $image = image_by_custom_field($args);
|
60 |
+
|
61 |
+
if(!$image && $attachment && $attachment !== 'false' && $attachment !== '0') $image = image_by_attachment($args);
|
62 |
+
|
63 |
+
if(!$image && $image_scan) $image = image_by_scan($args);
|
64 |
+
|
65 |
+
if(!$image && $default_image) $image = image_by_default($args);
|
66 |
+
|
67 |
+
if($image)
|
68 |
+
$image = display_the_image($args, $image);
|
69 |
+
|
70 |
+
else
|
71 |
+
$image = '<!-- No images were added to this post. -->';
|
72 |
+
|
73 |
+
if($echo && $echo !== 'false' && $echo !== '0' && $format !== 'array')
|
74 |
+
echo $image;
|
75 |
+
else
|
76 |
+
return $image;
|
77 |
+
}
|
78 |
+
|
79 |
+
/**
|
80 |
+
* Calls images by custom field key
|
81 |
+
* Allow looping through multiple custom fields
|
82 |
+
*
|
83 |
+
* @since 0.4
|
84 |
+
* @param $args Not Optional
|
85 |
+
* @return array $image, $classes, $alt
|
86 |
+
*/
|
87 |
+
function image_by_custom_field($args = array()) {
|
88 |
+
|
89 |
+
extract($args);
|
90 |
+
|
91 |
+
if(!$post_id)
|
92 |
+
global $post;
|
93 |
+
|
94 |
+
if(isset($custom_key)) :
|
95 |
+
foreach($custom_key as $custom) :
|
96 |
+
$image = get_post_meta($post->ID, $custom, true);
|
97 |
+
if($image) :
|
98 |
+
break;
|
99 |
+
endif;
|
100 |
+
endforeach;
|
101 |
+
if(!$image) :
|
102 |
+
return false;
|
103 |
+
endif;
|
104 |
+
endif;
|
105 |
+
|
106 |
+
return array('image' => $image);
|
107 |
+
}
|
108 |
+
|
109 |
+
/**
|
110 |
+
* Check for attachment images
|
111 |
+
* Uses get_children() to check if the post has images attached
|
112 |
+
*
|
113 |
+
* @since 0.4
|
114 |
+
* @param $args Not Optional
|
115 |
+
* @return array $image, $classes, $alt, $caption
|
116 |
+
*/
|
117 |
+
function image_by_attachment($args = array()) {
|
118 |
+
|
119 |
+
extract($args);
|
120 |
+
|
121 |
+
if(!$post_id)
|
122 |
+
global $post;
|
123 |
+
|
124 |
+
/*
|
125 |
+
* Use a WP 2.6 function to check
|
126 |
+
*/
|
127 |
+
if(function_exists('wp_enqueue_style')) :
|
128 |
+
$attachments = get_children(array('post_parent' => $post->ID, 'post_status' => 'inherit', 'post_type' => 'attachment', 'post_mime_type' => 'image', 'order' => 'ASC', 'orderby' => 'menu_order ID'));
|
129 |
+
|
130 |
+
/*
|
131 |
+
* WP 2.5 compatibility
|
132 |
+
*/
|
133 |
+
else :
|
134 |
+
$attachments = get_children("post_parent=$post->ID&post_type=attachment&post_mime_type=image&orderby=\"menu_order ASC, ID ASC\"");
|
135 |
+
|
136 |
+
endif;
|
137 |
+
|
138 |
+
if(empty($attachments)) :
|
139 |
+
return false;
|
140 |
+
else :
|
141 |
+
foreach($attachments as $id => $attachment) :
|
142 |
+
$i++;
|
143 |
+
if($i == $order_of_image) :
|
144 |
+
$image = wp_get_attachment_image_src($id, $default_size);
|
145 |
+
$image = $image[0];
|
146 |
+
break;
|
147 |
+
endif;
|
148 |
+
endforeach;
|
149 |
+
endif;
|
150 |
+
|
151 |
+
return array('image' => $image);
|
152 |
+
}
|
153 |
+
|
154 |
+
/**
|
155 |
+
* Scans the post for images within the content
|
156 |
+
* Not called by default with get_the_image()
|
157 |
+
* Shouldn't use if using large images within posts, better to use the other options
|
158 |
+
*
|
159 |
+
* @since 0.4
|
160 |
+
* @param $args Not Optional
|
161 |
+
* @return $image, $classes, $alt
|
162 |
+
*/
|
163 |
+
function image_by_scan($args = array()) {
|
164 |
+
|
165 |
+
if(!$post_id)
|
166 |
+
global $post;
|
167 |
+
|
168 |
+
preg_match_all('|<img.*?src=[\'"](.*?)[\'"].*?>|i', $post->post_content, $matches);
|
169 |
+
|
170 |
+
if(isset($matches)) $image = $matches[1][0];
|
171 |
+
|
172 |
+
if($matches[1][0])
|
173 |
+
return array('image' => $image);
|
174 |
+
else
|
175 |
+
return false;
|
176 |
+
}
|
177 |
+
|
178 |
+
/**
|
179 |
+
* Used for setting a default image
|
180 |
+
* Not used with get_the_image() by default
|
181 |
+
*
|
182 |
+
* @since 0.4
|
183 |
+
* @param $args Not Optional
|
184 |
+
* @return array $image, $classes, $alt
|
185 |
+
*/
|
186 |
+
function image_by_default($args = array()) {
|
187 |
+
|
188 |
+
extract($args);
|
189 |
+
|
190 |
+
$image = $default_image;
|
191 |
+
|
192 |
+
return array('image' => $image);
|
193 |
+
}
|
194 |
+
|
195 |
+
/**
|
196 |
+
* Formats an image with appropriate alt text and class
|
197 |
+
* Adds a link to the post if argument is set
|
198 |
+
* Should only be called if there is an image to display, but will handle it if not
|
199 |
+
*
|
200 |
+
* @since 0.1
|
201 |
+
* @param $args Not Optional
|
202 |
+
* @param $arr Array of image info ($image, $classes, $alt, $caption)
|
203 |
+
* @return string Formatted image (w/link to post if the option is set)
|
204 |
+
*/
|
205 |
+
function display_the_image($args = array(), $arr = false) {
|
206 |
+
global $post;
|
207 |
+
|
208 |
+
extract($arr);
|
209 |
+
|
210 |
+
if(!$image)
|
211 |
+
return;
|
212 |
+
|
213 |
+
extract($args);
|
214 |
+
|
215 |
+
if($width) $width = ' width="' . $width . '"';
|
216 |
+
if($height) $height = ' height="' . $height . '"';
|
217 |
+
|
218 |
+
$img = $image;
|
219 |
+
|
220 |
+
if(is_array($custom_key)) :
|
221 |
+
foreach($custom_key as $key) :
|
222 |
+
if($key !== 'false' && $key !== '0') :
|
223 |
+
$classes[] = str_replace(' ', '-', strtolower($key));
|
224 |
+
endif;
|
225 |
+
endforeach;
|
226 |
+
endif;
|
227 |
+
|
228 |
+
$classes[] = $default_size;
|
229 |
+
$classes[] = $image_class;
|
230 |
+
|
231 |
+
$class = join(' ', $classes);
|
232 |
+
|
233 |
+
$image = '';
|
234 |
+
|
235 |
+
if($format == 'array') :
|
236 |
+
$image = array(
|
237 |
+
'url' => $img,
|
238 |
+
'alt' => the_title_attribute('echo=0'),
|
239 |
+
'class' => $class,
|
240 |
+
'link' => get_permalink($post->ID),
|
241 |
+
);
|
242 |
+
return $image;
|
243 |
+
endif;
|
244 |
+
|
245 |
+
if($link_to_post)
|
246 |
+
$image .= '<a href="' . get_permalink($post->ID) . '" title="' . the_title_attribute('echo=0') . '">';
|
247 |
+
|
248 |
+
$image .= '<img src="' . $img . '" alt="' . the_title_attribute('echo=0') . '" class="' . $class . '"' . $width . $height . ' />';
|
249 |
+
|
250 |
+
if($link_to_post)
|
251 |
+
$image .= '</a>';
|
252 |
+
|
253 |
+
return $image;
|
254 |
+
}
|
255 |
+
|
256 |
+
/**
|
257 |
+
* Deprecated function needs to be replaced with get_the_image()
|
258 |
+
*
|
259 |
+
* @since 0.1
|
260 |
+
* @deprecated 0.4
|
261 |
+
*/
|
262 |
+
function get_the_image_link($deprecated = false, $deprecated_2 = false, $deprecated_3 = false) {
|
263 |
+
_e('The function has been deprecated. You need to update your template file calls to <code>get_the_image()</code>.','get_the_image');
|
264 |
+
}
|
265 |
+
?>
|
readme.css
ADDED
@@ -0,0 +1,280 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
/* Reset values */
|
2 |
+
html, body, div, span, object, h1, h2, h3, h4, h5, h6, p, blockquote, pre, a, abbr, acronym, address, big, cite, code, del, dfn, em, img, ins, kbd, q, samp, small, strong, sub, sup, tt, var, dl, dt, dd, ol, ul, li, fieldset, form, label, legend, table, caption, tbody, tfoot, thead, tr, th, td {
|
3 |
+
margin: 0;
|
4 |
+
padding: 0;
|
5 |
+
vertical-align: baseline;
|
6 |
+
outline: none;
|
7 |
+
font-size: 100%;
|
8 |
+
background: transparent;
|
9 |
+
border: none;
|
10 |
+
text-decoration: none;
|
11 |
+
}
|
12 |
+
|
13 |
+
/*
|
14 |
+
* Get rid of deprecated and non-semantic elements
|
15 |
+
* These elements should not be used and replaced with proper alternatives
|
16 |
+
*/
|
17 |
+
b, i, hr, u, center, menu, layer, s, strike, font, xmp {
|
18 |
+
margin: 0;
|
19 |
+
padding: 0;
|
20 |
+
vertical-align: baseline;
|
21 |
+
outline: none;
|
22 |
+
font-size: 100%;
|
23 |
+
font-weight: normal;
|
24 |
+
font-style: normal;
|
25 |
+
background: transparent;
|
26 |
+
border: none;
|
27 |
+
text-decoration: none;
|
28 |
+
}
|
29 |
+
font {
|
30 |
+
color: #333;
|
31 |
+
}
|
32 |
+
center {
|
33 |
+
text-align: left;
|
34 |
+
}
|
35 |
+
|
36 |
+
/* End deprecated elements */
|
37 |
+
|
38 |
+
|
39 |
+
/* Body */
|
40 |
+
body {
|
41 |
+
line-height: 24px;
|
42 |
+
font-family: Cambria, Georgia, Times, "Times New Roman", serif;
|
43 |
+
color: #333;
|
44 |
+
background: #fff;
|
45 |
+
}
|
46 |
+
|
47 |
+
/* Headers */
|
48 |
+
h1, h2, h3, h4, h5, h6 {
|
49 |
+
font-style: normal;
|
50 |
+
font-weight: normal;
|
51 |
+
margin: 0 0 21px 0;
|
52 |
+
}
|
53 |
+
h1 {
|
54 |
+
font-size: 1.8em;
|
55 |
+
}
|
56 |
+
h2 {
|
57 |
+
font-size: 1.7em;
|
58 |
+
}
|
59 |
+
h3 {
|
60 |
+
font-size: 1.55em;;
|
61 |
+
}
|
62 |
+
h4 {
|
63 |
+
font-size: 1.4em;
|
64 |
+
}
|
65 |
+
h5 {
|
66 |
+
font-size: 1.25em;
|
67 |
+
}
|
68 |
+
h6 {
|
69 |
+
font-size: 1.1em;
|
70 |
+
}
|
71 |
+
|
72 |
+
/* Paragraphs */
|
73 |
+
p {
|
74 |
+
margin: 0 0 21px 0;
|
75 |
+
}
|
76 |
+
|
77 |
+
/* Lists */
|
78 |
+
ol, ul {
|
79 |
+
list-style: none;
|
80 |
+
}
|
81 |
+
ul {
|
82 |
+
list-style: disc;
|
83 |
+
margin: 0 0 21px 1.5em;
|
84 |
+
}
|
85 |
+
ol {
|
86 |
+
list-style-type: decimal;
|
87 |
+
margin: 0 0 21px 3em;
|
88 |
+
}
|
89 |
+
ol ol {
|
90 |
+
list-style: upper-roman;
|
91 |
+
}
|
92 |
+
ol ol ol {
|
93 |
+
list-style: lower-roman;
|
94 |
+
}
|
95 |
+
ol ol ol ol {
|
96 |
+
list-style: upper-alpha;
|
97 |
+
}
|
98 |
+
ol ol ol ol ol {
|
99 |
+
list-style: lower-alpha;
|
100 |
+
}
|
101 |
+
ul ul, ol ol, ul ol, ol ul {
|
102 |
+
margin-bottom: 0;
|
103 |
+
}
|
104 |
+
dl {
|
105 |
+
margin: 0 0 18px 3px;
|
106 |
+
}
|
107 |
+
dl dt {
|
108 |
+
font-weight: bold;
|
109 |
+
margin: 12px 0 0 0;
|
110 |
+
}
|
111 |
+
dl dd {
|
112 |
+
margin: 6px 0 0 1.5em;
|
113 |
+
}
|
114 |
+
|
115 |
+
/* Text elements */
|
116 |
+
strong {
|
117 |
+
font-weight: bold;
|
118 |
+
}
|
119 |
+
strong strong {
|
120 |
+
font-weight: normal;
|
121 |
+
}
|
122 |
+
em, cite {
|
123 |
+
font-style: italic;
|
124 |
+
}
|
125 |
+
em em, cite cite {
|
126 |
+
font-style: normal;
|
127 |
+
}
|
128 |
+
abbr {
|
129 |
+
cursor: help;
|
130 |
+
}
|
131 |
+
acronym {
|
132 |
+
text-transform: uppercase;
|
133 |
+
border-bottom: 1px dashed #666;
|
134 |
+
cursor: help;
|
135 |
+
}
|
136 |
+
big {
|
137 |
+
font-size: 120%;
|
138 |
+
}
|
139 |
+
small, sup, sub {
|
140 |
+
font-size: 80%;
|
141 |
+
}
|
142 |
+
sup {
|
143 |
+
vertical-align: baseline;
|
144 |
+
position: relative;
|
145 |
+
bottom: 0.3em;
|
146 |
+
}
|
147 |
+
sub {
|
148 |
+
vertical-align: baseline;
|
149 |
+
position: relative;
|
150 |
+
top: 0.3em;
|
151 |
+
}
|
152 |
+
address {
|
153 |
+
font-style: italic;
|
154 |
+
margin: 0 0 21px 0;
|
155 |
+
}
|
156 |
+
li address, dd address {
|
157 |
+
margin: 0;
|
158 |
+
}
|
159 |
+
|
160 |
+
/* Blockquotes */
|
161 |
+
blockquote {
|
162 |
+
margin: 0 2.5em;
|
163 |
+
font-style: normal;
|
164 |
+
}
|
165 |
+
blockquote em, blockquote cite {
|
166 |
+
font-style: italic;
|
167 |
+
}
|
168 |
+
blockquote, q {
|
169 |
+
quotes: none;
|
170 |
+
}
|
171 |
+
blockquote:before, blockquote:after, q:before, q:after {
|
172 |
+
content: '';
|
173 |
+
content: none;
|
174 |
+
}
|
175 |
+
|
176 |
+
/* Links */
|
177 |
+
a {
|
178 |
+
cursor: pointer;
|
179 |
+
}
|
180 |
+
a img {
|
181 |
+
border: none;
|
182 |
+
}
|
183 |
+
|
184 |
+
/* Code */
|
185 |
+
pre {
|
186 |
+
font: .9em Monaco, monospace, Courier, "Courier New";
|
187 |
+
line-height: 21px;
|
188 |
+
margin-bottom: 21px;
|
189 |
+
padding: 9px;
|
190 |
+
}
|
191 |
+
code {
|
192 |
+
font: .9em Monaco, monospace, Courier, "Courier New";
|
193 |
+
}
|
194 |
+
pre code {
|
195 |
+
font-size: 1em;
|
196 |
+
}
|
197 |
+
|
198 |
+
/* Delete and insert */
|
199 |
+
ins, dfn {
|
200 |
+
font-style: italic;
|
201 |
+
text-decoration: none;
|
202 |
+
border-bottom: 1px solid #666;
|
203 |
+
}
|
204 |
+
del {
|
205 |
+
text-decoration: line-through;
|
206 |
+
}
|
207 |
+
|
208 |
+
/* Object */
|
209 |
+
object {
|
210 |
+
margin-bottom: 21px;
|
211 |
+
}
|
212 |
+
|
213 |
+
/* Forms */
|
214 |
+
input, textarea {
|
215 |
+
font-size: 1em;
|
216 |
+
font-family: Cambria, Georgia, Times, "Times New Roman", serif;
|
217 |
+
padding: 3px;
|
218 |
+
}
|
219 |
+
:focus {
|
220 |
+
outline: none;
|
221 |
+
}
|
222 |
+
form label {
|
223 |
+
cursor: pointer;
|
224 |
+
}
|
225 |
+
|
226 |
+
/* Tables */
|
227 |
+
table {
|
228 |
+
border-collapse: collapse;
|
229 |
+
border-spacing: 0;
|
230 |
+
margin-bottom: 21px;
|
231 |
+
}
|
232 |
+
th, td {
|
233 |
+
text-align: left;
|
234 |
+
}
|
235 |
+
|
236 |
+
/* Horizontal rule */
|
237 |
+
hr {
|
238 |
+
margin-bottom: 21px;
|
239 |
+
}
|
240 |
+
|
241 |
+
body {
|
242 |
+
width: 780px;
|
243 |
+
margin: 36px auto;
|
244 |
+
font: 14px/21px "Lucida Grande", "Lucida Sans Unicode", Tahoma, Verdana, sans-serif;
|
245 |
+
}
|
246 |
+
/* Links */
|
247 |
+
a:link, a:visited {
|
248 |
+
color: #2f6eb9;
|
249 |
+
text-decoration: none;
|
250 |
+
}
|
251 |
+
a:hover, a:active {
|
252 |
+
text-decoration: underline;
|
253 |
+
}
|
254 |
+
/* Headers */
|
255 |
+
h1, h2, h3, h4, h5, h6 {
|
256 |
+
margin-top: 36px;
|
257 |
+
color: #666;
|
258 |
+
font-family: Cambria, Georgia, Times, "Times New Roman", serif;
|
259 |
+
}
|
260 |
+
h1, h2 {
|
261 |
+
padding-bottom: 12px;
|
262 |
+
border-bottom: 1px solid #ccc;
|
263 |
+
}
|
264 |
+
h1 {
|
265 |
+
margin-top: 0;
|
266 |
+
font-size: 2.1em;
|
267 |
+
}
|
268 |
+
code {
|
269 |
+
padding: 0 3px;
|
270 |
+
background: #eee;
|
271 |
+
}
|
272 |
+
pre code {
|
273 |
+
padding: 0;
|
274 |
+
}
|
275 |
+
pre {
|
276 |
+
overflow: auto;
|
277 |
+
padding: 9px;
|
278 |
+
background: #eee;
|
279 |
+
border: 1px solid #ccc;
|
280 |
+
}
|
readme.html
ADDED
@@ -0,0 +1,229 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
|
2 |
+
<html xmlns="http://www.w3.org/1999/xhtml">
|
3 |
+
<head>
|
4 |
+
<meta http-equiv="Content-Type" content="text/html;charset=utf-8"/>
|
5 |
+
<title>A guide to the Get the Image plugin</title>
|
6 |
+
|
7 |
+
<link rel="stylesheet" href="readme.css" type="text/css" media="screen" />
|
8 |
+
|
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.
|
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 |
+
|
24 |
+
<p>This plugin was made to easily find images and add them on pages where the full post isn't shown. This is the order in which the plugin attempts to grab an image.</p>
|
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>
|
31 |
+
</ol>
|
32 |
+
|
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><?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><?php get_the_image('custom_key=Thumbnail,thumbnail&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><?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,
|
77 |
+
'image_class' => false,
|
78 |
+
'image_scan' => false,
|
79 |
+
'width' => false,
|
80 |
+
'height' => false,
|
81 |
+
'echo' => true
|
82 |
+
);</code></pre>
|
83 |
+
|
84 |
+
<dl>
|
85 |
+
<dt>custom_key</dt>
|
86 |
+
<dd>This parameter refers to a custom field key (or keys) that you use. Remember, custom field keys are case-sensitive (defaults are <code>Thumbnail</code> and <code>thumbnail</code>).</dd>
|
87 |
+
<dt>attachment</dt>
|
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>
|
94 |
+
<dd>You can choose for the script to grab something other than the first attached image. This only refers to image attachments.</dd>
|
95 |
+
<dt>link_to_post</dt>
|
96 |
+
<dd>Whether the attachment image should be linked to the post (set to <code>true</code> by default).</dd>
|
97 |
+
<dt>image_class</dt>
|
98 |
+
<dd>You can give an additional class to the image for use in your CSS.</dd>
|
99 |
+
<dt>image_scan</dt>
|
100 |
+
<dd>If set to <code>true</code>, the script will search within your post for an image that's been added.</dd>
|
101 |
+
<dt>width</dt>
|
102 |
+
<dd>Set the width of the image on output.</dd>
|
103 |
+
<dt>height</dt>
|
104 |
+
<dd>Set the height of the image on output.</dd>
|
105 |
+
<dt>echo</dt>
|
106 |
+
<dd>If set to <code>true</code>, the image is shown on the page. If set to <code>false</code>, the image will be returned to use in your own function. (Set to <code>true</code> by default.)</dd>
|
107 |
+
</dl>
|
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><?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><?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><?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><?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><?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><?php if(have_posts()) : while(have_posts()) : the_post(); ?>
|
154 |
+
|
155 |
+
<div class="hentry">
|
156 |
+
|
157 |
+
<?php get_the_image(array('custom_key' => array('feature_img'), 'default_size' => 'medium', 'width' => '200', 'height' => '200', 'image_class' => 'feature')); ?>
|
158 |
+
|
159 |
+
<h2><a href="<?php the_permalink(); ?>" title="<?php the_title_attribute(); ?>" rel="bookmark"><?php the_title(); ?></a></h2>
|
160 |
+
|
161 |
+
<div class="entry">
|
162 |
+
<?the_excerpt(); ?>
|
163 |
+
</div>
|
164 |
+
|
165 |
+
</div>
|
166 |
+
|
167 |
+
<?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><?php get_the_image('custom_key=feature_image&default_size=medium&width=200&height=200&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><?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 |
+
|
193 |
+
<pre><code>img.thumbnail { }</code></pre>
|
194 |
+
|
195 |
+
<p>Let's suppose you've used this code:</p>
|
196 |
+
|
197 |
+
<pre><code><?php get_the_image(array('custom_key' => array('Donkey Kong', 'mario'), 'default_size' => 'full')); ?></code></pre>
|
198 |
+
|
199 |
+
<p>This will give you these CSS classes to work with:</p>
|
200 |
+
|
201 |
+
<pre><code>img.full { }
|
202 |
+
img.donkey-kong { }
|
203 |
+
img.mario { }</code></pre>
|
204 |
+
|
205 |
+
<p>You can also input a custom CSS class like so:</p>
|
206 |
+
|
207 |
+
<pre><code><?php get_the_image(array('image_class' => 'custom-image')); ?></code></pre>
|
208 |
+
|
209 |
+
<p>You will still have the <code>default_size</code> and <code>custom_key</code> classes plus your additional class:</p>
|
210 |
+
|
211 |
+
<pre><code>img.custom-image { }
|
212 |
+
img.thumbnail { }</code></pre>
|
213 |
+
|
214 |
+
<h2>Plugin support</h2>
|
215 |
+
|
216 |
+
<p>I run a WordPress community called <a href="http://themehybrid.com" title="Theme Hybrid">Theme Hybrid</a>, which is where I fully support all of my WordPress projects, including plugins. You can sign up for an account to get plugin support for a small yearly fee ($25 <acronym title="United States Dollars">USD</acronym> at the time of writing).</p>
|
217 |
+
|
218 |
+
<p>I know. I know. You might not want to pay for support, but just consider it a donation to the project. I am fully employed through my work with WordPress, so to continue making cool, GPL-licensed plugins and having the time to support them, I must pay the bills.</p>
|
219 |
+
|
220 |
+
<h2>Copyright & 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 © Justin Tadlock</p>
|
227 |
+
|
228 |
+
</body>
|
229 |
+
</html>
|
readme.txt
ADDED
@@ -0,0 +1,69 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
=== Get the Image ===
|
2 |
+
Contributors: greenshady
|
3 |
+
Donate link: https://www.paypal.com/cgi-bin/webscr?cmd=_s-xclick&hosted_button_id=3687060
|
4 |
+
Tags: images, thumbnails
|
5 |
+
Requires at least: 2.5
|
6 |
+
Tested up to: 2.7.1
|
7 |
+
Stable tag: 0.3.1
|
8 |
+
|
9 |
+
An easy-to-use image script for adding things such as thumbnails and feature images.
|
10 |
+
|
11 |
+
== Description ==
|
12 |
+
|
13 |
+
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.
|
14 |
+
|
15 |
+
== Installation ==
|
16 |
+
|
17 |
+
1. Upload `get-the-image` to the `/wp-content/plugins/` directory.
|
18 |
+
1. Activate the plugin through the 'Plugins' menu in WordPress.
|
19 |
+
1. Go to <em>Appearance > Cleaner Gallery</em> to set your preferences.
|
20 |
+
|
21 |
+
More detailed instructions are included in the plugin's `readme.html` file. It is important to read through that file to properly understand all of the options and how the plugin works.
|
22 |
+
|
23 |
+
== Frequently Asked Questions ==
|
24 |
+
|
25 |
+
= Why was this plugin created? =
|
26 |
+
|
27 |
+
Many magazine-type themes require a lot of work when inputting images to make them look good. This plugin was developed to make that process much easier for the end user. But, at the same time, it needed to be flexible enough to handle anything.
|
28 |
+
|
29 |
+
Other scripts are bloated and offer odd solutions. This plugin uses the built-in methods of WordPress to create things such as feature images, thumbnails, galleries, or whatever.
|
30 |
+
|
31 |
+
This plugin was created to be a lightweight solution to handle a very powerful need in the WordPress community.
|
32 |
+
|
33 |
+
= How does it pull images? =
|
34 |
+
|
35 |
+
1. Looks for an image by custom field (one of your choosing).
|
36 |
+
1. If no image is found, it grabs an image attached to your post.
|
37 |
+
1. If no image is attached, it can extract an image from your post content (off by default).
|
38 |
+
1. If no image is found at this point, it will default to an image you set (not set by default).
|
39 |
+
|
40 |
+
= How do I add it to my theme? =
|
41 |
+
|
42 |
+
There are several methods, but in general, you would use this call:
|
43 |
+
|
44 |
+
`
|
45 |
+
<?php if ( function_exists( 'get_the_image' ) ) get_the_image(); ?>
|
46 |
+
`
|
47 |
+
|
48 |
+
To see all methods and options, refer to the `readme.html` file included with the theme download.
|
49 |
+
|
50 |
+
== Screenshots ==
|
51 |
+
|
52 |
+
You can view this plugin in action on my <a href="http://justintadlock.com" title="Justin Tadlock's blog">personal blog</a> (note the thumbnails).
|
53 |
+
|
54 |
+
== Changelog ==
|
55 |
+
|
56 |
+
Ealier versions were not documented well.
|
57 |
+
|
58 |
+
**Version 0.3.2**
|
59 |
+
|
60 |
+
* General code cleanup.
|
61 |
+
|
62 |
+
**Version 0.3.1**
|
63 |
+
|
64 |
+
* Fixed the default image and image scan features.
|
65 |
+
|
66 |
+
**Version 0.3**
|
67 |
+
|
68 |
+
* Changed methods of calling the image script.
|
69 |
+
* Added more parameters.
|