Version Description
- Update FAQ. Clean up
readme
. Don't yellnull
. Don't output link to original if there is no image.
Download this release
Release Info
Developer | chrisscott |
Plugin | Multiple Post Thumbnails |
Version | 1.1 |
Comparing to | |
See all releases |
Code changes from version 1.0 to 1.1
- multi-post-thumbnails.php +4 -4
- readme.txt +48 -29
multi-post-thumbnails.php
CHANGED
@@ -3,7 +3,7 @@
|
|
3 |
Plugin Name: Multiple Post Thumbnails
|
4 |
Plugin URI: http://wordpress.org/extend/plugins/multiple-post-thumbnails/
|
5 |
Description: Adds the ability to add multiple post thumbnails to a post type.
|
6 |
-
Version: 1.
|
7 |
Author: Chris Scott
|
8 |
Author URI: http://vocecommuncations.com/
|
9 |
*/
|
@@ -236,7 +236,7 @@ if (!class_exists('MultiPostThumbnails')) {
|
|
236 |
$html = '';
|
237 |
}
|
238 |
|
239 |
-
if ($link_to_original) {
|
240 |
$html = sprintf('<a href="%s">%s</a>', wp_get_attachment_url($post_thumbnail_id), $html);
|
241 |
}
|
242 |
|
@@ -278,7 +278,7 @@ if (!class_exists('MultiPostThumbnails')) {
|
|
278 |
* @param string $thumbnail_id The thumbnail's post ID.
|
279 |
* @return string HTML
|
280 |
*/
|
281 |
-
private function post_thumbnail_html($thumbnail_id =
|
282 |
global $content_width, $_wp_additional_image_sizes, $post_ID;
|
283 |
|
284 |
$set_thumbnail_link = sprintf('<p class="hide-if-no-js"><a title="%1$s" href="%2$s" id="set-%3$s-%4$s-thumbnail" class="thickbox">%%s</a></p>', esc_attr__( "Set {$this->label}" ), get_upload_iframe_src('image'), $this->post_type, $this->id);
|
@@ -319,7 +319,7 @@ if (!class_exists('MultiPostThumbnails')) {
|
|
319 |
|
320 |
if ($thumbnail_id == '-1') {
|
321 |
delete_post_meta($post_ID, "{$this->post_type}_{$this->id}_thumbnail_id");
|
322 |
-
die($this->post_thumbnail_html(
|
323 |
}
|
324 |
|
325 |
if ($thumbnail_id && get_post($thumbnail_id)) {
|
3 |
Plugin Name: Multiple Post Thumbnails
|
4 |
Plugin URI: http://wordpress.org/extend/plugins/multiple-post-thumbnails/
|
5 |
Description: Adds the ability to add multiple post thumbnails to a post type.
|
6 |
+
Version: 1.1
|
7 |
Author: Chris Scott
|
8 |
Author URI: http://vocecommuncations.com/
|
9 |
*/
|
236 |
$html = '';
|
237 |
}
|
238 |
|
239 |
+
if ($link_to_original && $html) {
|
240 |
$html = sprintf('<a href="%s">%s</a>', wp_get_attachment_url($post_thumbnail_id), $html);
|
241 |
}
|
242 |
|
278 |
* @param string $thumbnail_id The thumbnail's post ID.
|
279 |
* @return string HTML
|
280 |
*/
|
281 |
+
private function post_thumbnail_html($thumbnail_id = null) {
|
282 |
global $content_width, $_wp_additional_image_sizes, $post_ID;
|
283 |
|
284 |
$set_thumbnail_link = sprintf('<p class="hide-if-no-js"><a title="%1$s" href="%2$s" id="set-%3$s-%4$s-thumbnail" class="thickbox">%%s</a></p>', esc_attr__( "Set {$this->label}" ), get_upload_iframe_src('image'), $this->post_type, $this->id);
|
319 |
|
320 |
if ($thumbnail_id == '-1') {
|
321 |
delete_post_meta($post_ID, "{$this->post_type}_{$this->id}_thumbnail_id");
|
322 |
+
die($this->post_thumbnail_html(null));
|
323 |
}
|
324 |
|
325 |
if ($thumbnail_id && get_post($thumbnail_id)) {
|
readme.txt
CHANGED
@@ -1,9 +1,9 @@
|
|
1 |
=== Plugin Name ===
|
2 |
Contributors: chrisscott
|
3 |
-
Tags: thumbnails, image
|
4 |
Requires at least: 2.9.2
|
5 |
-
Tested up to: 3.2
|
6 |
-
Stable tag: 1.
|
7 |
|
8 |
Adds multiple post thumbnails to a post type. If you've ever wanted more than one Featured Image on a post, this plugin is for you.
|
9 |
|
@@ -11,21 +11,20 @@ Adds multiple post thumbnails to a post type. If you've ever wanted more than on
|
|
11 |
|
12 |
1. Upload the `multi-post-thumbnails` directory to the `/wp-content/plugins/` directory
|
13 |
2. Activate the plugin through the 'Plugins' menu in WordPress
|
14 |
-
3.
|
15 |
-
|
16 |
-
|
17 |
-
|
18 |
-
|
19 |
-
|
20 |
-
|
21 |
-
|
22 |
-
|
23 |
-
|
|
|
24 |
4. Display the thumbnail in your theme:
|
25 |
|
26 |
-
|
27 |
-
&& MultiPostThumbnails::has_post_thumbnail('post', 'secondary-image')) :
|
28 |
-
MultiPostThumbnails::the_post_thumbnail('post', 'secondary-image'); endif; ?>
|
29 |
|
30 |
== Frequently Asked Questions ==
|
31 |
|
@@ -37,30 +36,46 @@ This is caused by using the example in previous readmes that didn't do a check f
|
|
37 |
|
38 |
You can loop through an array of the post types:
|
39 |
|
40 |
-
|
41 |
-
|
42 |
-
|
43 |
-
|
44 |
-
|
45 |
-
|
46 |
-
|
47 |
-
|
48 |
-
|
49 |
-
|
50 |
-
|
51 |
|
52 |
= How do I use a custom thumbnail size in my theme? =
|
53 |
|
54 |
After you have registered a new post thumbnail, register a new image size for it. e.g if your post thumbnail `id` is `secondary-image` and it is for a `post`, it probably makes sense to use something like:
|
55 |
|
56 |
-
|
57 |
|
58 |
This will register a new image size of 250x150 px. Then, when you display the thumbnail in your theme, update the call to `MultiPostThumbnails::the_post_thumbnail()` to pass in the image size:
|
59 |
|
60 |
-
|
61 |
|
62 |
You can register multiple image sizes for a given thumbnail if desired.
|
63 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
64 |
== Screenshots ==
|
65 |
|
66 |
1. Admin meta box showing a new thumbnail named 'Secondary Image'.
|
@@ -69,6 +84,10 @@ You can register multiple image sizes for a given thumbnail if desired.
|
|
69 |
|
70 |
== Changelog ==
|
71 |
|
|
|
|
|
|
|
|
|
72 |
= 1.0 =
|
73 |
|
74 |
* Use `get_the_ID()` in `get_the_post_thumbnail`. Props helgatheviking.
|
1 |
=== Plugin Name ===
|
2 |
Contributors: chrisscott
|
3 |
+
Tags: thumbnails, image, featured image
|
4 |
Requires at least: 2.9.2
|
5 |
+
Tested up to: 3.3.2
|
6 |
+
Stable tag: 1.1
|
7 |
|
8 |
Adds multiple post thumbnails to a post type. If you've ever wanted more than one Featured Image on a post, this plugin is for you.
|
9 |
|
11 |
|
12 |
1. Upload the `multi-post-thumbnails` directory to the `/wp-content/plugins/` directory
|
13 |
2. Activate the plugin through the 'Plugins' menu in WordPress
|
14 |
+
3. In your theme's `functions.php` register a new thumbnail for the post type you want it active for. If `post_type` is not set it defaults to `post`.
|
15 |
+
|
16 |
+
if (class_exists('MultiPostThumbnails')) {
|
17 |
+
new MultiPostThumbnails(
|
18 |
+
array(
|
19 |
+
'label' => 'Secondary Image',
|
20 |
+
'id' => 'secondary-image',
|
21 |
+
'post_type' => 'post'
|
22 |
+
)
|
23 |
+
);
|
24 |
+
}
|
25 |
4. Display the thumbnail in your theme:
|
26 |
|
27 |
+
<?php if (class_exists('MultiPostThumbnails')) : MultiPostThumbnails::the_post_thumbnail('post', 'secondary-image'); endif; ?>
|
|
|
|
|
28 |
|
29 |
== Frequently Asked Questions ==
|
30 |
|
36 |
|
37 |
You can loop through an array of the post types:
|
38 |
|
39 |
+
if (class_exists('MultiPostThumbnails')) {
|
40 |
+
$types = array('post', 'page', 'my_post_type');
|
41 |
+
foreach($types as $type) {
|
42 |
+
new MultiPostThumbnails(array(
|
43 |
+
'label' => 'Secondary Image',
|
44 |
+
'id' => 'secondary-image',
|
45 |
+
'post_type' => $type
|
46 |
+
)
|
47 |
+
);
|
48 |
+
}
|
49 |
+
}
|
50 |
|
51 |
= How do I use a custom thumbnail size in my theme? =
|
52 |
|
53 |
After you have registered a new post thumbnail, register a new image size for it. e.g if your post thumbnail `id` is `secondary-image` and it is for a `post`, it probably makes sense to use something like:
|
54 |
|
55 |
+
add_image_size('post-secondary-image-thumbnail', 250, 150);
|
56 |
|
57 |
This will register a new image size of 250x150 px. Then, when you display the thumbnail in your theme, update the call to `MultiPostThumbnails::the_post_thumbnail()` to pass in the image size:
|
58 |
|
59 |
+
MultiPostThumbnails::the_post_thumbnail('post', 'secondary-image', NULL, 'post-secondary-image-thumbnail');
|
60 |
|
61 |
You can register multiple image sizes for a given thumbnail if desired.
|
62 |
|
63 |
+
= How do I get just the URL of a thumbnail without the wrapping HTML? =
|
64 |
+
|
65 |
+
Use `MultiPostThumbnails::get_post_thumbnail_url()` passing in the following arguments:
|
66 |
+
|
67 |
+
* `$post_type` - the post type the thumbnail was registered for
|
68 |
+
* `$id` - the ID used to register the thumbnail (not the post ID)
|
69 |
+
* `$post_id` - optional and only needs to be passed in when outside the loop but should be passed in if available when called
|
70 |
+
|
71 |
+
For example, for a thumbnail registered with an `id` of `secondary-image` and `post_type` of `post` the following would retrieve the thumbnail URL:
|
72 |
+
|
73 |
+
MultiPostThumbnails::get_post_thumbnail_url('post', 'secondary-image');
|
74 |
+
|
75 |
+
= I see the meta box in the admin when editing a post but when I click on 'Set as [label] image' in the media manager, nothing happens and I get a JavaScript console error =
|
76 |
+
|
77 |
+
If you are using a symlink to include the plugin directory in your project, the admin js file will not load and cause this. Unfortunately, the solution is to not use symlinks due to the behavior of PHP's `__FILE__`
|
78 |
+
|
79 |
== Screenshots ==
|
80 |
|
81 |
1. Admin meta box showing a new thumbnail named 'Secondary Image'.
|
84 |
|
85 |
== Changelog ==
|
86 |
|
87 |
+
= 1.1 =
|
88 |
+
|
89 |
+
* Update FAQ. Clean up `readme`. Don't yell `null`. Don't output link to original if there is no image.
|
90 |
+
|
91 |
= 1.0 =
|
92 |
|
93 |
* Use `get_the_ID()` in `get_the_post_thumbnail`. Props helgatheviking.
|