Version Description
- Filter
dfi_thumbnail_id
now also returns the post ID of the post (or any postype) that is being called. See the FAQ for new examples
=
Download this release
Release Info
Developer | janw.oostendorp |
Plugin | Default featured image |
Version | 1.3 |
Comparing to | |
See all releases |
Code changes from version 1.2 to 1.3
- readme.txt +53 -38
- set-default-featured-image.php +2 -2
readme.txt
CHANGED
@@ -2,8 +2,8 @@
|
|
2 |
Contributors: janwoostendorp
|
3 |
Tags: media, image
|
4 |
Requires at least: 3.5
|
5 |
-
Tested up to:
|
6 |
-
Stable tag: 1.
|
7 |
License: GPLv2 or later
|
8 |
License URI: http://www.gnu.org/licenses/gpl-2.0.html
|
9 |
|
@@ -38,41 +38,50 @@ This plugin can't guarantee that it works. That depends on the themes. Still I w
|
|
38 |
The plugin uses the default WordPress functions `the_post_thumbnail` or `get_the_post_thumbnail`. `has_post_thumbnail` will always return true. `get_post_thumbnail_id` will return the ID set on the post or the DFI you set.
|
39 |
|
40 |
= Can I exclude a page or give it a different image? =
|
41 |
-
|
42 |
-
|
43 |
-
|
44 |
-
|
45 |
-
|
46 |
-
|
47 |
-
|
48 |
-
|
49 |
-
|
50 |
-
|
51 |
-
|
52 |
-
|
53 |
-
|
54 |
-
|
55 |
-
|
56 |
-
|
57 |
-
|
58 |
-
|
59 |
-
|
60 |
-
|
61 |
-
|
62 |
-
|
63 |
-
|
64 |
-
|
65 |
-
|
66 |
-
|
67 |
-
|
68 |
-
|
69 |
-
|
70 |
-
|
71 |
-
|
72 |
-
|
73 |
-
|
74 |
-
|
75 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
76 |
|
77 |
= Can I change the HTML of the image returned? =
|
78 |
yes you can with the filter `dfi_thumbnail_html`.
|
@@ -104,7 +113,13 @@ yes you can with the filter `dfi_thumbnail_html`.
|
|
104 |
= 1.1 =
|
105 |
* Fixed inheriting classes of the image
|
106 |
|
|
|
|
|
|
|
|
|
|
|
|
|
107 |
== Upgrade Notice ==
|
108 |
|
109 |
= 1.0 =
|
110 |
-
Update makes sure that the set image will show. Everywhere.
|
2 |
Contributors: janwoostendorp
|
3 |
Tags: media, image
|
4 |
Requires at least: 3.5
|
5 |
+
Tested up to: 4.1
|
6 |
+
Stable tag: 1.3
|
7 |
License: GPLv2 or later
|
8 |
License URI: http://www.gnu.org/licenses/gpl-2.0.html
|
9 |
|
38 |
The plugin uses the default WordPress functions `the_post_thumbnail` or `get_the_post_thumbnail`. `has_post_thumbnail` will always return true. `get_post_thumbnail_id` will return the ID set on the post or the DFI you set.
|
39 |
|
40 |
= Can I exclude a page or give it a different image? =
|
41 |
+
Yes you can by using the buildin `dfi_thumbnail_id` filter. It will give you the post id which you can use to check against.
|
42 |
+
|
43 |
+
**Don't use a featured image on page 23**
|
44 |
+
|
45 |
+
function dfi_skip_page ( $dfi_id, $post_id ) {
|
46 |
+
if ( $post_id == 23 ) {
|
47 |
+
return 0; // invalid id
|
48 |
+
}
|
49 |
+
return $dfi_id; // the original featured image id
|
50 |
+
}
|
51 |
+
add_filter( 'dfi_thumbnail_id', 'dfi_skip_page', 10 , 2 );
|
52 |
+
|
53 |
+
**Use a different image for some categories**
|
54 |
+
|
55 |
+
The example below only works if the post has 'animals' as a category. Asigning just 'cats' won't work
|
56 |
+
To do that just don't nest the `if`
|
57 |
+
|
58 |
+
function dfi_category ( $dfi_id, $post_id ) {
|
59 |
+
// all which have 'animals' as a category
|
60 |
+
if ( has_category( 'animals', $post_id ) ) {
|
61 |
+
|
62 |
+
//sub category
|
63 |
+
if ( has_category( 'cats', $post_id ) ) {
|
64 |
+
return 7; // cats img
|
65 |
+
} else if has_category( 'dogs', $post_id ) {
|
66 |
+
return 8; // dogs img
|
67 |
+
}
|
68 |
+
|
69 |
+
return 6; // default animals picture
|
70 |
+
}
|
71 |
+
return $dfi_id; // the original featured image id
|
72 |
+
}
|
73 |
+
add_filter( 'dfi_thumbnail_id', 'dfi_category', 10, 2 );
|
74 |
+
|
75 |
+
**Different image for the posttype 'wiki'**
|
76 |
+
|
77 |
+
function dfi_posttype_book ( $dfi_id, $post_id ) {
|
78 |
+
$post = get_post($post_id);
|
79 |
+
if ( 'wiki' === $post->post_type ) {
|
80 |
+
return 31; // the image id
|
81 |
+
}
|
82 |
+
return $dfi_id; // the original featured image id
|
83 |
+
}
|
84 |
+
add_filter( 'dfi_thumbnail_id', 'dfi_posttype_book', 10, 2 );
|
85 |
|
86 |
= Can I change the HTML of the image returned? =
|
87 |
yes you can with the filter `dfi_thumbnail_html`.
|
113 |
= 1.1 =
|
114 |
* Fixed inheriting classes of the image
|
115 |
|
116 |
+
= 1.2 =
|
117 |
+
* Filter `dfi_thumbnail_id` is now called in an earlier stage.
|
118 |
+
|
119 |
+
= 1.3 =
|
120 |
+
* Filter `dfi_thumbnail_id` now also returns the post ID of the post (or any postype) that is being called. See the FAQ for new examples
|
121 |
+
|
122 |
== Upgrade Notice ==
|
123 |
|
124 |
= 1.0 =
|
125 |
+
Update makes sure that the set image will show. Everywhere.
|
set-default-featured-image.php
CHANGED
@@ -3,7 +3,7 @@
|
|
3 |
* plugin name: Default featured image
|
4 |
* Plugin URI: http://wordpress.org/extend/plugins/default-featured-image/
|
5 |
* Description: Allows users to select a default feartured image in the media settings
|
6 |
-
* Version: 1.
|
7 |
* Author: Jan Willem Oostendorp
|
8 |
* License: GPLv2 or later
|
9 |
*/
|
@@ -82,7 +82,7 @@ class default_featured_image
|
|
82 |
|
83 |
if ($single)
|
84 |
// allow to set an other ID see the readme.txt for details
|
85 |
-
return apply_filters( 'dfi_thumbnail_id', get_option( 'dfi_image_id' ) ); // set the default featured img ID
|
86 |
else
|
87 |
return array();
|
88 |
}
|
3 |
* plugin name: Default featured image
|
4 |
* Plugin URI: http://wordpress.org/extend/plugins/default-featured-image/
|
5 |
* Description: Allows users to select a default feartured image in the media settings
|
6 |
+
* Version: 1.3
|
7 |
* Author: Jan Willem Oostendorp
|
8 |
* License: GPLv2 or later
|
9 |
*/
|
82 |
|
83 |
if ($single)
|
84 |
// allow to set an other ID see the readme.txt for details
|
85 |
+
return apply_filters( 'dfi_thumbnail_id', get_option( 'dfi_image_id' ), $object_id ); // set the default featured img ID
|
86 |
else
|
87 |
return array();
|
88 |
}
|