-
Notifications
You must be signed in to change notification settings - Fork 0
/
widget-app-genres.php
144 lines (124 loc) · 3.69 KB
/
widget-app-genres.php
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
<?php
class iFavorites_App_Genre_Widget extends WP_Widget {
function __construct()
{
parent::__construct(
'app_genre_widget',
__("App Genres", 'ifavorites'),
array(
'description' => __("A list or dropdown of app genres", 'ifavorites'),
)
);
}
function widget($args, $instance)
{
extract($args);
echo $before_widget;
$title = apply_filters('widget_title', $instance['title']);
if (empty($title)) $title = __("App Genres", 'ifavorites');
if ($title) echo $before_title.$title.$after_title;
$args = array(
'taxonomy' => 'app_genre',
'orderby' => 'name',
'show_count' => $instance['count'],
'hierarchical' => $instance['hierachical'],
'hide_empty' => !$instance['show_empty'],
);
if ($instance['dropdown']) {
wp_dropdown_categories(array_merge($args, array(
'id' => 'app_genre_widget_dropdown',
'name' => 'app_genre',
'show_option_all' => __("Select Genre", 'ifavorites'),
)));
?>
<script>
document.getElementById('app_genre_widget_dropdown').onchange = function() {
var genre_id = this.options[this.selectedIndex].value;
if (genre_id > 0) location.href = "<?=home_url()?>/?app_genre="+genre_id;
}
</script>
<?php
} else {
echo '<ul>';
wp_list_categories(array_merge($args, array(
'title_li' => '',
)));
echo '</ul>';
}
echo $after_widget;
}
function update($new_instance, $old_instance)
{
return array_merge($old_instance, array(
'title' => strip_tags($new_instance['title']),
'dropdown' => !empty($new_instance['dropdown']),
'count' => !empty($new_instance['count']),
'hierarchical' => !empty($new_instance['hierarchical']),
'show_empty' => !empty($new_instance['show_empty']),
));
}
function form($instance)
{
$title = isset($instance['title']) ? $instance['title'] : '';
$dropdown = isset($instance['dropdown']) ? (bool) $instance['dropdown'] : false;
$count = isset($instance['count']) ? (bool) $instance['count'] : false;
$hierarchical = isset($instance['hierarchical']) ? (bool) $instance['hierarchical'] : false;
$show_empty = isset($instance['show_empty']) ? (bool) $instance['show_empty'] : false;
?>
<p>
<label for="<?=$this->get_field_id('title')?>">
<?=__("Title:", 'ifavorites')?>
</label>
<input
type="text"
class="widefat"
id="<?=$this->get_field_id('title')?>"
name="<?=esc_attr($this->get_field_name('title'))?>"
value="<?=esc_attr($title)?>"
/>
</p>
<p>
<input
type="checkbox"
class="checkbox"
id="<?=$this->get_field_id('dropdown')?>"
name="<?=esc_attr($this->get_field_name('dropdown'))?>"
<?php checked($dropdown); ?>
/>
<label for="<?=$this->get_field_id('dropdown')?>">
<?=__("Display as dropdown", 'ifavorites')?>
</label><br/>
<input
type="checkbox"
class="checkbox"
id="<?=$this->get_field_id('count')?>"
name="<?=esc_attr($this->get_field_name('count'))?>"
<?php checked($count); ?>
/>
<label for="<?=$this->get_field_id('count')?>">
<?=__("Show post counts", 'ifavorites')?>
</label><br/>
<input
type="checkbox"
class="checkbox"
id="<?=$this->get_field_id('hierarchical')?>"
name="<?=esc_attr($this->get_field_name('hierarchical'))?>"
<?php checked($hierarchical); ?>
/>
<label for="<?=$this->get_field_id('hierarchical')?>">
<?=__("Show hierarchy", 'ifavorites')?>
</label><br/>
<input
type="checkbox"
class="checkbox"
id="<?=$this->get_field_id('show_empty')?>"
name="<?=esc_attr($this->get_field_name('show_empty'))?>"
<?php checked($show_empty); ?>
/>
<label for="<?=$this->get_field_id('show_empty')?>">
<?=__("Show empty genres", 'ifavorites')?>
</label>
</p>
<?php
}
}