Version Description
The First Release
Download this release
Release Info
Developer | elzahlan |
Plugin | Categories Images |
Version | 1.0 |
Comparing to | |
See all releases |
Version 1.0
- categories-images.php +91 -0
- readme.txt +49 -0
categories-images.php
ADDED
@@ -0,0 +1,91 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
/*
|
3 |
+
Plugin Name: Categories Images
|
4 |
+
Plugin URI: http://zahlan.net/blog/2012/06/categories-images/
|
5 |
+
Description: Categories Images Plugin allow you to add an image to category or any custom term.
|
6 |
+
Author: Muhammad Said El Zahlan
|
7 |
+
Version: 1.0
|
8 |
+
Author URI: http://zahlan.net/
|
9 |
+
*/
|
10 |
+
?>
|
11 |
+
<?php
|
12 |
+
// inti the plugin
|
13 |
+
add_action('admin_head', 'z_inti');
|
14 |
+
function z_inti() {
|
15 |
+
$z_taxonomies = get_taxonomies();
|
16 |
+
if (is_array($z_taxonomies)) {
|
17 |
+
foreach ($z_taxonomies as $z_taxonomy ) {
|
18 |
+
add_action($z_taxonomy.'_add_form_fields', 'z_add_texonomy_field');
|
19 |
+
add_action($z_taxonomy.'_edit_form_fields', 'z_edit_texonomy_field');
|
20 |
+
}
|
21 |
+
}
|
22 |
+
}
|
23 |
+
|
24 |
+
// add image field in add form
|
25 |
+
function z_add_texonomy_field() {
|
26 |
+
wp_enqueue_style('thickbox');
|
27 |
+
echo '<div class="form-field">
|
28 |
+
<label for="taxonomy_image">Image</label>
|
29 |
+
<input type="text" name="taxonomy_image" id="taxonomy_image" value="" />
|
30 |
+
</div>'.z_script();
|
31 |
+
}
|
32 |
+
|
33 |
+
// add image field in edit form
|
34 |
+
function z_edit_texonomy_field($taxonomy) {
|
35 |
+
wp_enqueue_style('thickbox');
|
36 |
+
echo '<tr class="form-field">
|
37 |
+
<th scope="row" valign="top"><label for="taxonomy_image">Image</label></th>
|
38 |
+
<td><input type="text" name="taxonomy_image" id="taxonomy_image" value="'.get_option('z_taxonomy_image'.$taxonomy->term_id).'" /><br /></td>
|
39 |
+
</tr>'.z_script();
|
40 |
+
}
|
41 |
+
|
42 |
+
wp_enqueue_script('thickbox');
|
43 |
+
|
44 |
+
function z_script() {
|
45 |
+
return '<script type="text/javascript">
|
46 |
+
jQuery(document).ready(function() {
|
47 |
+
var fileInput = "";
|
48 |
+
jQuery("#taxonomy_image").live("click",
|
49 |
+
function() {
|
50 |
+
fileInput = jQuery("#taxonomy_image");
|
51 |
+
tb_show("", "media-upload.php?type=image&TB_iframe=true");
|
52 |
+
return false;
|
53 |
+
});
|
54 |
+
window.original_send_to_editor = window.send_to_editor;
|
55 |
+
window.send_to_editor = function(html) {
|
56 |
+
if (fileInput) {
|
57 |
+
fileurl = jQuery("img", html).attr("src");
|
58 |
+
if (!fileurl)
|
59 |
+
fileurl = jQuery(html).attr("src");
|
60 |
+
|
61 |
+
jQuery(fileInput).val(fileurl);
|
62 |
+
tb_remove();
|
63 |
+
}
|
64 |
+
else
|
65 |
+
window.original_send_to_editor(html);
|
66 |
+
};
|
67 |
+
});
|
68 |
+
</script>';
|
69 |
+
}
|
70 |
+
|
71 |
+
// save our taxonomy image while edit or save term
|
72 |
+
add_action('edit_term','z_save_taxonomy_image');
|
73 |
+
add_action('create_term','z_save_taxonomy_image');
|
74 |
+
function z_save_taxonomy_image($term_id) {
|
75 |
+
if(isset($_POST['taxonomy_image']))
|
76 |
+
update_option('z_taxonomy_image'.$term_id, $_POST['taxonomy_image']);
|
77 |
+
}
|
78 |
+
|
79 |
+
// output taxonomy image url for the given term_id (NULL by default)
|
80 |
+
function z_taxonomy_image_url($term_id = NULL) {
|
81 |
+
if (!$term_id) {
|
82 |
+
if (is_category())
|
83 |
+
$term_id = get_query_var('cat');
|
84 |
+
elseif (is_tax()) {
|
85 |
+
$current_term = get_term_by('slug', get_query_var('term'), get_query_var('taxonomy'));
|
86 |
+
$term_id = $current_term->term_id;
|
87 |
+
}
|
88 |
+
}
|
89 |
+
return get_option('z_taxonomy_image'.$term_id);
|
90 |
+
}
|
91 |
+
?>
|
readme.txt
ADDED
@@ -0,0 +1,49 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
=== Categories Images ===
|
2 |
+
Contributors: elzahlan
|
3 |
+
Tags: Category Image, Categories Images, admin, texonomy image, category icon, category logo
|
4 |
+
Requires at least: 2.8
|
5 |
+
Tested up to: 3.3.2
|
6 |
+
Stable tag: 1.0
|
7 |
+
|
8 |
+
The Categories Images Plugin allow you to add image with category or taxonomy.
|
9 |
+
|
10 |
+
== Description ==
|
11 |
+
|
12 |
+
The Categories Images Plugin allow you to add image with category or taxonomy.
|
13 |
+
|
14 |
+
Use `<?php if (function_exists('z_taxonomy_image_url')) echo z_taxonomy_image_url(); ?>` to get the url and put it in any <img /> tag in (category or taxonomy) template.
|
15 |
+
|
16 |
+
== Installation ==
|
17 |
+
|
18 |
+
You can install Categories Images directly from the WordPress admin panel:
|
19 |
+
|
20 |
+
1. Visit the Plugins > Add New and search for 'Categories Images'.
|
21 |
+
2. Click to install.
|
22 |
+
3. Once installed, activate and it is functional.
|
23 |
+
|
24 |
+
OR
|
25 |
+
|
26 |
+
Manual Installation:
|
27 |
+
|
28 |
+
1. Download the plugin, then extract it.
|
29 |
+
2. Upload `categories-images` extracted folder to the `/wp-content/plugins/` directory
|
30 |
+
3. Activate the plugin through the 'Plugins' menu in WordPress
|
31 |
+
|
32 |
+
You're done! The Plugin ready to use, for more please check the plugin description.
|
33 |
+
|
34 |
+
= More documentation =
|
35 |
+
|
36 |
+
Go to [http://zahlan.net/blog/2012/06/categories-images/](http://zahlan.net/blog/2012/06/categories-images/)
|
37 |
+
|
38 |
+
== Frequently Asked Questions ==
|
39 |
+
|
40 |
+
None
|
41 |
+
|
42 |
+
== Screenshots ==
|
43 |
+
|
44 |
+
None
|
45 |
+
|
46 |
+
== Changelog ==
|
47 |
+
|
48 |
+
= 1.0 =
|
49 |
+
The First Release
|