This repository has been archived by the owner on Mar 1, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 2
/
readme.txt
158 lines (91 loc) · 4.77 KB
/
readme.txt
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
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
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
=== Taxonomy Thumbnail ===
Contributors: GregLone
Tags: thumbnail, image, taxonomy, category, dev
Requires at least: 3.5
Tested up to: 4.2.2
Stable tag: trunk
License: GPLv3
License URI: http://www.screenfeed.fr/gpl-v3.txt
Add a thumbnail to your taxonomy terms.
== Description ==
This plugin is meant for developers, it allows to attach a thumbnail to taxonomy terms.
= UI for setting the thumbnails =
The thumbnail can be added on term creation or later on the term edition page.
The terms list has a column displaying the current thumbnail (so far, no specific action here).
The plugin uses the "new" media window (the one used since WP 3.5), not the old thickbox.
I made some extra efforts to enhance accessibility. I'm not an a11y expert but the UI is not only a "Add thumbnail" button. For instance, the new `wp.a11y.speak()` is used when available. Please give me feedback if you think it can be improved.
Works with or without JavaScript.
If JavaScript is enabled, thumbnails are set via ajax, no need to update the terms.
By default, the UI is displayed for all public taxonomies, but this can be filtered that way:
add_filter( 'sftth_taxonomies', 'my_taxonomies_with_thumbnail' );
function my_taxonomies_with_thumbnail( $taxonomies ) {
unset( $taxonomies['post_tag'] );
$taxonomies['my_custom_tax'] = 'my_custom_tax';
return $taxonomies;
}
= Template tags =
Find them in `inc/template-tags.php`.
All of them use `term_taxonomy_id`, not `term_id`. This way we don't need to specify the taxonomy. I tried to mimic the post thumbnail functions.
Retrieve term thumbnail ID:
get_term_thumbnail_id( $term_taxonomy_id )
Check if term has a thumbnail attached:
has_term_thumbnail( $term_taxonomy_id )
Display the term thumbnail:
the_term_thumbnail( $term_taxonomy_id, $size = 'post-thumbnail', $attr = '' )
Retrieve the term thumbnail:
get_term_thumbnail( $term_taxonomy_id, $size = 'post-thumbnail', $attr = '' )
Set a term thumbnail:
set_term_thumbnail( $term_taxonomy_id, $thumbnail_id )
Remove a term thumbnail:
delete_term_thumbnail( $term_taxonomy_id )
= Store the data =
There are two ways to store the thumbnail IDs:
1. Use term metas with the plugin [Meta for Taxonomies](https://wordpress.org/plugins/meta-for-taxonomies/).
1. Use an option (an array association of `term_taxonomy_id` => `thumbnail_id` integers). The option name can be customized by defining the constant `SFTTH_OPTION_NAME` in `wp-config.php`.
Side note: there is no upgrade system to switch from one to the other.
= Get terms =
Use `get_terms()` with a specific parameter to retrieve only terms with a thumbnail:
$terms = get_terms( array(
'with_thumbnail' => true,
) );
If you use the plugin *Meta for Taxonomies*, you should always cache thumbnails:
$terms = get_terms( array(
'with_thumbnail' => false,
) );
Summary:
1. `'with_thumbnail' => true`: cache thumbnails, retrieve only terms with a thumbnail.
1. `'with_thumbnail' => false`: cache thumbnails, retrieve all terms.
= Uninstall =
When uninstalling the plugin, you can decide to not delete the thumbnails, simply define a constant in `wp-config.php`:
define( 'SFTTH_KEEP_DATA', true );
= Translations =
* US English
* French
= Requirements =
Should work starting from WP 3.5, but tested only in WP 4.2.2 so far.
= Credits =
Photo used for the banner by [Nicolas Janik](https://www.flickr.com/photos/n1colas/2598073727/) ([CC BY 2.0](https://creativecommons.org/licenses/by/2.0/)).
== Installation ==
1. Extract the plugin folder from the downloaded ZIP file.
1. Upload the `sf-taxonomy-thumbnail` folder to your `/wp-content/plugins/` directory.
1. Activate the plugin from the "Plugins" page.
1. If you want to use term metas instead of an option, install the plugin [Meta for Taxonomies](https://wordpress.org/plugins/meta-for-taxonomies/).
== Frequently Asked Questions ==
= Do I need to cache thumbnails in `get_terms()` if I don't use term metas? =
No, the option is already cached by WordPress.
= Why should I use the plugin Meta for Taxonomies? =
I think it's the proper way to store this kind of data. Post thumbnails are stored in post metas, right? So term thumbnails should be stored in term metas.
But it requires a plugin, WordPress does not provide a term metas system yet. And I don't want to force you to use a dependency, so I wanted my plugin to also work without it.
= Any plan for a settings page where I can choose the taxonomies? =
Nope, it will not happen, there is no point to do so.
= Other questions? =
Eventually, try the [WordPress support forum](http://wordpress.org/support/plugin/sf-move-login).
== Screenshots ==
1. Create a new category an assign a thumbnail.
2. Change or remove the thumbnail from the category.
== Changelog ==
= 1.0 =
* 2015/06/11
* Initial release.
== Upgrade Notice ==
First release.