@@ -13,241 +13,241 @@ discard block |
||
13 | 13 | */ |
14 | 14 | class geodir_cpt_categories_widget extends WP_Widget { |
15 | 15 | |
16 | - /** |
|
17 | - * Register the cpt categories with WordPress. |
|
18 | - * |
|
19 | - * @since 1.5.4 |
|
20 | - */ |
|
21 | - public function __construct() { |
|
22 | - $widget_ops = array('classname' => 'geodir_cpt_categories_widget', 'description' => __('A list of GeoDirectory CPT categories.', 'geodirectory')); |
|
23 | - parent::__construct('geodir_cpt_categories_widget', __('GD > CPT Categories', 'geodirectory'), $widget_ops); |
|
24 | - } |
|
25 | - |
|
26 | - /** |
|
27 | - * Front-end display content for cpt categories widget. |
|
28 | - * |
|
29 | - * @since 1.5.4 |
|
30 | - * @since 1.6.6 New parameters $no_cpt_filter &no_cat_filter added. |
|
31 | - * |
|
32 | - * @param array $args Widget arguments. |
|
33 | - * @param array $instance Saved values from database. |
|
34 | - */ |
|
35 | - public function widget($args, $instance) { |
|
36 | - $params = array(); |
|
37 | - /** |
|
38 | - * Filter the widget title. |
|
39 | - * |
|
40 | - * @since 1.5.4 |
|
41 | - * |
|
42 | - * @param string $title The widget title. Default empty. |
|
43 | - * @param array $instance An array of the widget's settings. |
|
44 | - * @param mixed $id_base The widget ID. |
|
45 | - */ |
|
46 | - $params['title'] = apply_filters('geodir_cpt_categories_widget_title', empty($instance['title']) ? '' : $instance['title'], $instance, $this->id_base); |
|
47 | - |
|
48 | - /** |
|
49 | - * Filter the widget setting post type. |
|
50 | - * |
|
51 | - * @since 1.5.4 |
|
52 | - * |
|
53 | - * @param array $post_type The post types to display categories. |
|
54 | - * @param array $instance An array of the widget's settings. |
|
55 | - * @param mixed $id_base The widget ID. |
|
56 | - */ |
|
57 | - $params['post_type'] = apply_filters('geodir_cpt_categories_widget_post_type', empty($instance['post_type']) ? array() : $instance['post_type'], $instance, $this->id_base); |
|
58 | - |
|
59 | - /** |
|
60 | - * Filter the widget setting to hide empty categories. |
|
61 | - * |
|
62 | - * @since 1.5.4 |
|
63 | - * |
|
64 | - * @param bool $hide_empty If true then empty category will be not displayed. |
|
65 | - * @param array $instance An array of the widget's settings. |
|
66 | - * @param mixed $id_base The widget ID. |
|
67 | - */ |
|
68 | - $params['hide_empty'] = apply_filters('geodir_cpt_categories_widget_hide_empty', empty($instance['hide_empty']) ? 0 : 1, $instance, $this->id_base); |
|
69 | - |
|
70 | - /** |
|
71 | - * Filter the widget setting to show/hide category count. |
|
72 | - * |
|
73 | - * @since 1.5.4 |
|
74 | - * |
|
75 | - * @param bool $show_count If true then category count will be displayed. |
|
76 | - * @param array $instance An array of the widget's settings. |
|
77 | - * @param mixed $id_base The widget ID. |
|
78 | - */ |
|
79 | - $params['show_count'] = apply_filters('geodir_cpt_categories_widget_show_count', empty($instance['show_count']) ? 0 : 1, $instance, $this->id_base); |
|
80 | - |
|
81 | - /** |
|
82 | - * Filter the widget setting to show/hide category icon. |
|
83 | - * |
|
84 | - * @since 1.5.4 |
|
85 | - * |
|
86 | - * @param bool $hide_icon If true then category icon will be not displayed. |
|
87 | - * @param array $instance An array of the widget's settings. |
|
88 | - * @param mixed $id_base The widget ID. |
|
89 | - */ |
|
90 | - $params['hide_icon'] = apply_filters('geodir_cpt_categories_widget_hide_icon', empty($instance['hide_icon']) ? 0 : 1, $instance, $this->id_base); |
|
91 | - |
|
92 | - /** |
|
93 | - * Filter the widget setting to show CPT inline or not. |
|
94 | - * |
|
95 | - * @since 1.5.4 |
|
96 | - * |
|
97 | - * @param bool $cpt_left If true then CPT will be displayed inline. |
|
98 | - * @param array $instance An array of the widget's settings. |
|
99 | - * @param mixed $id_base The widget ID. |
|
100 | - */ |
|
101 | - $params['cpt_left'] = apply_filters('geodir_cpt_categories_widget_cpt_left', empty($instance['cpt_left']) ? 0 : 1, $instance, $this->id_base); |
|
102 | - |
|
103 | - /** |
|
104 | - * Filter the widget categories sorting order settings. |
|
105 | - * |
|
106 | - * @since 1.5.4 |
|
107 | - * |
|
108 | - * @param string $max_count Widget max no of sub-categories count. Default 'count'. |
|
109 | - * @param array $instance An array of the widget's settings. |
|
110 | - * @param mixed $id_base The widget ID. |
|
111 | - */ |
|
112 | - $params['sort_by'] = apply_filters('geodir_cpt_categories_widget_sort_by', isset($instance['sort_by']) && in_array($instance['sort_by'], array('az', 'count')) ? $instance['sort_by'] : 'count', $instance, $this->id_base); |
|
113 | - |
|
114 | - /** |
|
115 | - * Filter the widget max no of sub-categories count. |
|
116 | - * |
|
117 | - * @since 1.5.4 |
|
118 | - * |
|
119 | - * @param bool|string $max_count Widget max no of sub-categories count. |
|
120 | - * @param array $instance An array of the widget's settings. |
|
121 | - * @param mixed $id_base The widget ID. |
|
122 | - */ |
|
123 | - $params['max_count'] = apply_filters('geodir_cpt_categories_widget_max_count', !isset($instance['max_count']) ? 'all' : strip_tags($instance['max_count']), $instance, $this->id_base); |
|
124 | - |
|
125 | - /** |
|
126 | - * Filter the widget max sub-categories depth. |
|
127 | - * |
|
128 | - * @since 1.5.4 |
|
129 | - * |
|
130 | - * @param bool|string $max_level Widget max sub-categories depth. |
|
131 | - * @param array $instance An array of the widget's settings. |
|
132 | - * @param mixed $id_base The widget ID. |
|
133 | - */ |
|
134 | - $params['max_level'] = apply_filters('geodir_cpt_categories_widget_max_level', !isset($instance['max_level']) ? 'all' : strip_tags($instance['max_level']), $instance, $this->id_base); |
|
16 | + /** |
|
17 | + * Register the cpt categories with WordPress. |
|
18 | + * |
|
19 | + * @since 1.5.4 |
|
20 | + */ |
|
21 | + public function __construct() { |
|
22 | + $widget_ops = array('classname' => 'geodir_cpt_categories_widget', 'description' => __('A list of GeoDirectory CPT categories.', 'geodirectory')); |
|
23 | + parent::__construct('geodir_cpt_categories_widget', __('GD > CPT Categories', 'geodirectory'), $widget_ops); |
|
24 | + } |
|
25 | + |
|
26 | + /** |
|
27 | + * Front-end display content for cpt categories widget. |
|
28 | + * |
|
29 | + * @since 1.5.4 |
|
30 | + * @since 1.6.6 New parameters $no_cpt_filter &no_cat_filter added. |
|
31 | + * |
|
32 | + * @param array $args Widget arguments. |
|
33 | + * @param array $instance Saved values from database. |
|
34 | + */ |
|
35 | + public function widget($args, $instance) { |
|
36 | + $params = array(); |
|
37 | + /** |
|
38 | + * Filter the widget title. |
|
39 | + * |
|
40 | + * @since 1.5.4 |
|
41 | + * |
|
42 | + * @param string $title The widget title. Default empty. |
|
43 | + * @param array $instance An array of the widget's settings. |
|
44 | + * @param mixed $id_base The widget ID. |
|
45 | + */ |
|
46 | + $params['title'] = apply_filters('geodir_cpt_categories_widget_title', empty($instance['title']) ? '' : $instance['title'], $instance, $this->id_base); |
|
47 | + |
|
48 | + /** |
|
49 | + * Filter the widget setting post type. |
|
50 | + * |
|
51 | + * @since 1.5.4 |
|
52 | + * |
|
53 | + * @param array $post_type The post types to display categories. |
|
54 | + * @param array $instance An array of the widget's settings. |
|
55 | + * @param mixed $id_base The widget ID. |
|
56 | + */ |
|
57 | + $params['post_type'] = apply_filters('geodir_cpt_categories_widget_post_type', empty($instance['post_type']) ? array() : $instance['post_type'], $instance, $this->id_base); |
|
58 | + |
|
59 | + /** |
|
60 | + * Filter the widget setting to hide empty categories. |
|
61 | + * |
|
62 | + * @since 1.5.4 |
|
63 | + * |
|
64 | + * @param bool $hide_empty If true then empty category will be not displayed. |
|
65 | + * @param array $instance An array of the widget's settings. |
|
66 | + * @param mixed $id_base The widget ID. |
|
67 | + */ |
|
68 | + $params['hide_empty'] = apply_filters('geodir_cpt_categories_widget_hide_empty', empty($instance['hide_empty']) ? 0 : 1, $instance, $this->id_base); |
|
69 | + |
|
70 | + /** |
|
71 | + * Filter the widget setting to show/hide category count. |
|
72 | + * |
|
73 | + * @since 1.5.4 |
|
74 | + * |
|
75 | + * @param bool $show_count If true then category count will be displayed. |
|
76 | + * @param array $instance An array of the widget's settings. |
|
77 | + * @param mixed $id_base The widget ID. |
|
78 | + */ |
|
79 | + $params['show_count'] = apply_filters('geodir_cpt_categories_widget_show_count', empty($instance['show_count']) ? 0 : 1, $instance, $this->id_base); |
|
80 | + |
|
81 | + /** |
|
82 | + * Filter the widget setting to show/hide category icon. |
|
83 | + * |
|
84 | + * @since 1.5.4 |
|
85 | + * |
|
86 | + * @param bool $hide_icon If true then category icon will be not displayed. |
|
87 | + * @param array $instance An array of the widget's settings. |
|
88 | + * @param mixed $id_base The widget ID. |
|
89 | + */ |
|
90 | + $params['hide_icon'] = apply_filters('geodir_cpt_categories_widget_hide_icon', empty($instance['hide_icon']) ? 0 : 1, $instance, $this->id_base); |
|
91 | + |
|
92 | + /** |
|
93 | + * Filter the widget setting to show CPT inline or not. |
|
94 | + * |
|
95 | + * @since 1.5.4 |
|
96 | + * |
|
97 | + * @param bool $cpt_left If true then CPT will be displayed inline. |
|
98 | + * @param array $instance An array of the widget's settings. |
|
99 | + * @param mixed $id_base The widget ID. |
|
100 | + */ |
|
101 | + $params['cpt_left'] = apply_filters('geodir_cpt_categories_widget_cpt_left', empty($instance['cpt_left']) ? 0 : 1, $instance, $this->id_base); |
|
102 | + |
|
103 | + /** |
|
104 | + * Filter the widget categories sorting order settings. |
|
105 | + * |
|
106 | + * @since 1.5.4 |
|
107 | + * |
|
108 | + * @param string $max_count Widget max no of sub-categories count. Default 'count'. |
|
109 | + * @param array $instance An array of the widget's settings. |
|
110 | + * @param mixed $id_base The widget ID. |
|
111 | + */ |
|
112 | + $params['sort_by'] = apply_filters('geodir_cpt_categories_widget_sort_by', isset($instance['sort_by']) && in_array($instance['sort_by'], array('az', 'count')) ? $instance['sort_by'] : 'count', $instance, $this->id_base); |
|
113 | + |
|
114 | + /** |
|
115 | + * Filter the widget max no of sub-categories count. |
|
116 | + * |
|
117 | + * @since 1.5.4 |
|
118 | + * |
|
119 | + * @param bool|string $max_count Widget max no of sub-categories count. |
|
120 | + * @param array $instance An array of the widget's settings. |
|
121 | + * @param mixed $id_base The widget ID. |
|
122 | + */ |
|
123 | + $params['max_count'] = apply_filters('geodir_cpt_categories_widget_max_count', !isset($instance['max_count']) ? 'all' : strip_tags($instance['max_count']), $instance, $this->id_base); |
|
124 | + |
|
125 | + /** |
|
126 | + * Filter the widget max sub-categories depth. |
|
127 | + * |
|
128 | + * @since 1.5.4 |
|
129 | + * |
|
130 | + * @param bool|string $max_level Widget max sub-categories depth. |
|
131 | + * @param array $instance An array of the widget's settings. |
|
132 | + * @param mixed $id_base The widget ID. |
|
133 | + */ |
|
134 | + $params['max_level'] = apply_filters('geodir_cpt_categories_widget_max_level', !isset($instance['max_level']) ? 'all' : strip_tags($instance['max_level']), $instance, $this->id_base); |
|
135 | 135 | |
136 | - /** |
|
137 | - * Filter the widget setting to disable filter current viewing post type. |
|
138 | - * |
|
139 | - * @since 1.6.6 |
|
140 | - * |
|
141 | - * @param bool $no_cpt_filter If true then it doesn't filter current viewing post type. |
|
142 | - * @param array $instance An array of the widget's settings. |
|
143 | - * @param mixed $id_base The widget ID. |
|
144 | - */ |
|
145 | - $params['no_cpt_filter'] = apply_filters('geodir_cpt_categories_widget_no_cpt_filter', empty($instance['no_cpt_filter']) ? 0 : 1, $instance, $this->id_base); |
|
136 | + /** |
|
137 | + * Filter the widget setting to disable filter current viewing post type. |
|
138 | + * |
|
139 | + * @since 1.6.6 |
|
140 | + * |
|
141 | + * @param bool $no_cpt_filter If true then it doesn't filter current viewing post type. |
|
142 | + * @param array $instance An array of the widget's settings. |
|
143 | + * @param mixed $id_base The widget ID. |
|
144 | + */ |
|
145 | + $params['no_cpt_filter'] = apply_filters('geodir_cpt_categories_widget_no_cpt_filter', empty($instance['no_cpt_filter']) ? 0 : 1, $instance, $this->id_base); |
|
146 | 146 | |
147 | - /** |
|
148 | - * Filter the widget setting to disable current viewing category. |
|
149 | - * |
|
150 | - * @since 1.6.6 |
|
151 | - * |
|
152 | - * @param bool $no_cat_filter If true then it doesn't filter current viewing category. |
|
153 | - * @param array $instance An array of the widget's settings. |
|
154 | - * @param mixed $id_base The widget ID. |
|
155 | - */ |
|
156 | - $params['no_cat_filter'] = apply_filters('geodir_cpt_categories_widget_no_cat_filter', empty($instance['no_cat_filter']) ? 0 : 1, $instance, $this->id_base); |
|
157 | - |
|
158 | - /** |
|
159 | - * Filter the widget parameters. |
|
160 | - * |
|
161 | - * @since 1.5.4 |
|
162 | - * |
|
163 | - * @param array $params The widget parameters. |
|
164 | - * @param array $instance An array of the widget's settings. |
|
165 | - * @param mixed $id_base The widget ID. |
|
166 | - */ |
|
167 | - $params = apply_filters('geodir_cpt_categories_widget_params', $params, $instance, $this->id_base); |
|
168 | - |
|
169 | - $output = geodir_cpt_categories_output($params); |
|
170 | - |
|
171 | - echo $args['before_widget']; |
|
172 | - if ( $params['title'] ) { |
|
173 | - echo '<div class="geodir_list_heading clearfix">'; |
|
174 | - echo $args['before_title'] . $params['title'] . $args['after_title']; |
|
175 | - echo '</div>'; |
|
176 | - } |
|
177 | - echo '<div class="gd-cptcats-widget">'; |
|
178 | - echo $output; |
|
179 | - echo '</div>'; |
|
180 | - echo $args['after_widget']; |
|
181 | - } |
|
182 | - |
|
183 | - /** |
|
184 | - * Sanitize cpt categories widget values as they are saved. |
|
185 | - * |
|
186 | - * @since 1.5.4 |
|
187 | - * @since 1.6.6 New parameters $no_cpt_filter &no_cat_filter added. |
|
188 | - * |
|
189 | - * @param array $new_instance Values just sent to be saved. |
|
190 | - * @param array $old_instance Previously saved values from database. |
|
191 | - * |
|
192 | - * @return array Updated safe values to be saved. |
|
193 | - */ |
|
194 | - public function update($new_instance, $old_instance) { |
|
195 | - $new_instance['post_type'] = is_array($new_instance['post_type']) && in_array('0', $new_instance['post_type']) ? array('0') : $new_instance['post_type']; |
|
196 | - $instance = $old_instance; |
|
197 | - $instance['title'] = strip_tags($new_instance['title']); |
|
198 | - $instance['post_type'] = isset($new_instance['post_type']) ? $new_instance['post_type'] : array('0'); |
|
199 | - $instance['hide_empty'] = !empty($new_instance['hide_empty']) ? 1 : 0; |
|
200 | - $instance['show_count'] = !empty($new_instance['show_count']) ? 1 : 0; |
|
201 | - $instance['hide_icon'] = !empty($new_instance['hide_icon']) ? 1 : 0; |
|
202 | - $instance['cpt_left'] = !empty($new_instance['cpt_left']) ? 1 : 0; |
|
203 | - $instance['sort_by'] = isset($new_instance['sort_by']) && in_array($new_instance['sort_by'], array('az', 'count')) ? $new_instance['sort_by'] : 'count'; |
|
204 | - $instance['max_count'] = strip_tags($new_instance['max_count']); |
|
205 | - $instance['max_level'] = strip_tags($new_instance['max_level']); |
|
206 | - $instance['no_cpt_filter'] = !empty($new_instance['no_cpt_filter']) ? 1 : 0; |
|
207 | - $instance['no_cat_filter'] = !empty($new_instance['no_cat_filter']) ? 1 : 0; |
|
208 | - |
|
209 | - return $instance; |
|
210 | - } |
|
211 | - |
|
212 | - /** |
|
213 | - * Back-end cpt categories settings form. |
|
214 | - * |
|
215 | - * @since 1.5.4 |
|
216 | - * @since 1.6.6 New parameters $no_cpt_filter &no_cat_filter added. |
|
217 | - * |
|
218 | - * @param array $instance Previously saved values from database. |
|
219 | - */ |
|
220 | - public function form($instance) { |
|
221 | - $instance = wp_parse_args( (array)$instance, |
|
222 | - array( |
|
223 | - 'title' => '', |
|
224 | - 'post_type' => array(), // NULL for all |
|
225 | - 'hide_empty' => '', |
|
226 | - 'show_count' => '', |
|
227 | - 'hide_icon' => '', |
|
228 | - 'cpt_left' => '', |
|
229 | - 'sort_by' => 'count', |
|
230 | - 'max_count' => 'all', |
|
231 | - 'max_level' => '1', |
|
232 | - 'no_cpt_filter' => '', |
|
233 | - 'no_cat_filter' => '', |
|
234 | - ) |
|
235 | - ); |
|
236 | - |
|
237 | - $title = strip_tags($instance['title']); |
|
238 | - $post_type = $instance['post_type']; |
|
239 | - $hide_empty = !empty($instance['hide_empty']) ? true : false; |
|
240 | - $show_count = !empty($instance['show_count']) ? true : false; |
|
241 | - $hide_icon = !empty($instance['hide_icon']) ? true : false; |
|
242 | - $cpt_left = !empty($instance['cpt_left']) ? true : false; |
|
243 | - $max_count = strip_tags($instance['max_count']); |
|
244 | - $max_level = strip_tags($instance['max_level']); |
|
245 | - $sort_by = isset($instance['sort_by']) && in_array($instance['sort_by'], array('az', 'count')) ? $instance['sort_by'] : 'count'; |
|
246 | - $no_cpt_filter = !empty($instance['no_cpt_filter']) ? true : false; |
|
247 | - $no_cat_filter = !empty($instance['no_cat_filter']) ? true : false; |
|
248 | - |
|
249 | - $post_type_options = geodir_get_posttypes('options'); |
|
250 | - ?> |
|
147 | + /** |
|
148 | + * Filter the widget setting to disable current viewing category. |
|
149 | + * |
|
150 | + * @since 1.6.6 |
|
151 | + * |
|
152 | + * @param bool $no_cat_filter If true then it doesn't filter current viewing category. |
|
153 | + * @param array $instance An array of the widget's settings. |
|
154 | + * @param mixed $id_base The widget ID. |
|
155 | + */ |
|
156 | + $params['no_cat_filter'] = apply_filters('geodir_cpt_categories_widget_no_cat_filter', empty($instance['no_cat_filter']) ? 0 : 1, $instance, $this->id_base); |
|
157 | + |
|
158 | + /** |
|
159 | + * Filter the widget parameters. |
|
160 | + * |
|
161 | + * @since 1.5.4 |
|
162 | + * |
|
163 | + * @param array $params The widget parameters. |
|
164 | + * @param array $instance An array of the widget's settings. |
|
165 | + * @param mixed $id_base The widget ID. |
|
166 | + */ |
|
167 | + $params = apply_filters('geodir_cpt_categories_widget_params', $params, $instance, $this->id_base); |
|
168 | + |
|
169 | + $output = geodir_cpt_categories_output($params); |
|
170 | + |
|
171 | + echo $args['before_widget']; |
|
172 | + if ( $params['title'] ) { |
|
173 | + echo '<div class="geodir_list_heading clearfix">'; |
|
174 | + echo $args['before_title'] . $params['title'] . $args['after_title']; |
|
175 | + echo '</div>'; |
|
176 | + } |
|
177 | + echo '<div class="gd-cptcats-widget">'; |
|
178 | + echo $output; |
|
179 | + echo '</div>'; |
|
180 | + echo $args['after_widget']; |
|
181 | + } |
|
182 | + |
|
183 | + /** |
|
184 | + * Sanitize cpt categories widget values as they are saved. |
|
185 | + * |
|
186 | + * @since 1.5.4 |
|
187 | + * @since 1.6.6 New parameters $no_cpt_filter &no_cat_filter added. |
|
188 | + * |
|
189 | + * @param array $new_instance Values just sent to be saved. |
|
190 | + * @param array $old_instance Previously saved values from database. |
|
191 | + * |
|
192 | + * @return array Updated safe values to be saved. |
|
193 | + */ |
|
194 | + public function update($new_instance, $old_instance) { |
|
195 | + $new_instance['post_type'] = is_array($new_instance['post_type']) && in_array('0', $new_instance['post_type']) ? array('0') : $new_instance['post_type']; |
|
196 | + $instance = $old_instance; |
|
197 | + $instance['title'] = strip_tags($new_instance['title']); |
|
198 | + $instance['post_type'] = isset($new_instance['post_type']) ? $new_instance['post_type'] : array('0'); |
|
199 | + $instance['hide_empty'] = !empty($new_instance['hide_empty']) ? 1 : 0; |
|
200 | + $instance['show_count'] = !empty($new_instance['show_count']) ? 1 : 0; |
|
201 | + $instance['hide_icon'] = !empty($new_instance['hide_icon']) ? 1 : 0; |
|
202 | + $instance['cpt_left'] = !empty($new_instance['cpt_left']) ? 1 : 0; |
|
203 | + $instance['sort_by'] = isset($new_instance['sort_by']) && in_array($new_instance['sort_by'], array('az', 'count')) ? $new_instance['sort_by'] : 'count'; |
|
204 | + $instance['max_count'] = strip_tags($new_instance['max_count']); |
|
205 | + $instance['max_level'] = strip_tags($new_instance['max_level']); |
|
206 | + $instance['no_cpt_filter'] = !empty($new_instance['no_cpt_filter']) ? 1 : 0; |
|
207 | + $instance['no_cat_filter'] = !empty($new_instance['no_cat_filter']) ? 1 : 0; |
|
208 | + |
|
209 | + return $instance; |
|
210 | + } |
|
211 | + |
|
212 | + /** |
|
213 | + * Back-end cpt categories settings form. |
|
214 | + * |
|
215 | + * @since 1.5.4 |
|
216 | + * @since 1.6.6 New parameters $no_cpt_filter &no_cat_filter added. |
|
217 | + * |
|
218 | + * @param array $instance Previously saved values from database. |
|
219 | + */ |
|
220 | + public function form($instance) { |
|
221 | + $instance = wp_parse_args( (array)$instance, |
|
222 | + array( |
|
223 | + 'title' => '', |
|
224 | + 'post_type' => array(), // NULL for all |
|
225 | + 'hide_empty' => '', |
|
226 | + 'show_count' => '', |
|
227 | + 'hide_icon' => '', |
|
228 | + 'cpt_left' => '', |
|
229 | + 'sort_by' => 'count', |
|
230 | + 'max_count' => 'all', |
|
231 | + 'max_level' => '1', |
|
232 | + 'no_cpt_filter' => '', |
|
233 | + 'no_cat_filter' => '', |
|
234 | + ) |
|
235 | + ); |
|
236 | + |
|
237 | + $title = strip_tags($instance['title']); |
|
238 | + $post_type = $instance['post_type']; |
|
239 | + $hide_empty = !empty($instance['hide_empty']) ? true : false; |
|
240 | + $show_count = !empty($instance['show_count']) ? true : false; |
|
241 | + $hide_icon = !empty($instance['hide_icon']) ? true : false; |
|
242 | + $cpt_left = !empty($instance['cpt_left']) ? true : false; |
|
243 | + $max_count = strip_tags($instance['max_count']); |
|
244 | + $max_level = strip_tags($instance['max_level']); |
|
245 | + $sort_by = isset($instance['sort_by']) && in_array($instance['sort_by'], array('az', 'count')) ? $instance['sort_by'] : 'count'; |
|
246 | + $no_cpt_filter = !empty($instance['no_cpt_filter']) ? true : false; |
|
247 | + $no_cat_filter = !empty($instance['no_cat_filter']) ? true : false; |
|
248 | + |
|
249 | + $post_type_options = geodir_get_posttypes('options'); |
|
250 | + ?> |
|
251 | 251 | <p><label for="<?php echo $this->get_field_id('title'); ?>"><?php _e('Title:', 'geodirectory'); ?></label> <input class="widefat" id="<?php echo $this->get_field_id('title'); ?>" name="<?php echo $this->get_field_name('title'); ?>" type="text" value="<?php echo esc_attr($title); ?>" /></p> |
252 | 252 | <p> |
253 | 253 | <label for="<?php echo $this->get_field_id('post_type'); ?>"><?php _e('Select CPT:', 'geodirectory'); ?></label> |
@@ -298,7 +298,7 @@ discard block |
||
298 | 298 | <label for="<?php echo $this->get_field_id('no_cat_filter'); ?>"><?php _e( 'Don\'t filter for current viewing category', 'geodirectory' ); ?></label> |
299 | 299 | </p> |
300 | 300 | <?php |
301 | - } |
|
301 | + } |
|
302 | 302 | } // class geodir_cpt_categories_widget |
303 | 303 | |
304 | 304 | register_widget('geodir_cpt_categories_widget'); |
@@ -316,179 +316,179 @@ discard block |
||
316 | 316 | * @return string CPT categories content. |
317 | 317 | */ |
318 | 318 | function geodir_cpt_categories_output($params) { |
319 | - global $post, $gd_use_query_vars; |
|
319 | + global $post, $gd_use_query_vars; |
|
320 | 320 | |
321 | - $old_gd_use_query_vars = $gd_use_query_vars; |
|
321 | + $old_gd_use_query_vars = $gd_use_query_vars; |
|
322 | 322 | |
323 | - $gd_use_query_vars = geodir_is_page('detail') ? true : false; |
|
323 | + $gd_use_query_vars = geodir_is_page('detail') ? true : false; |
|
324 | 324 | |
325 | - $args = wp_parse_args((array)$params, |
|
326 | - array( |
|
327 | - 'title' => '', |
|
328 | - 'post_type' => array(), // NULL for all |
|
329 | - 'hide_empty' => '', |
|
330 | - 'show_count' => '', |
|
331 | - 'hide_icon' => '', |
|
332 | - 'cpt_left' => '', |
|
333 | - 'sort_by' => 'count', |
|
334 | - 'max_count' => 'all', |
|
335 | - 'max_level' => '1', |
|
336 | - 'no_cpt_filter' => '', |
|
337 | - 'no_cat_filter' => '', |
|
338 | - ) |
|
339 | - ); |
|
340 | - |
|
341 | - $sort_by = isset($args['sort_by']) && in_array($args['sort_by'], array('az', 'count')) ? $args['sort_by'] : 'count'; |
|
342 | - $cpt_filter = empty($args['no_cpt_filter']) ? true : false; |
|
343 | - $cat_filter = empty($args['no_cat_filter']) ? true : false; |
|
344 | - |
|
345 | - $gd_post_types = geodir_get_posttypes('array'); |
|
346 | - |
|
347 | - $post_type_arr = !is_array($args['post_type']) ? explode(',', $args['post_type']) : $args['post_type']; |
|
348 | - $current_posttype = geodir_get_current_posttype(); |
|
349 | - |
|
350 | - $is_listing = false; |
|
351 | - $is_detail = false; |
|
352 | - $is_category = false; |
|
353 | - $post_ID = 0; |
|
354 | - $is_listing_page = geodir_is_page('listing'); |
|
355 | - $is_detail_page = geodir_is_page('detail'); |
|
356 | - if ($is_listing_page || $is_detail_page) { |
|
357 | - $current_posttype = geodir_get_current_posttype(); |
|
358 | - |
|
359 | - if ($current_posttype != '' && isset($gd_post_types[$current_posttype])) { |
|
360 | - if ($is_detail_page) { |
|
361 | - $is_detail = true; |
|
362 | - $post_ID = is_object($post) && !empty($post->ID) ? (int)$post->ID : 0; |
|
363 | - } else { |
|
364 | - $is_listing = true; |
|
365 | - if (is_tax()) { // category page |
|
366 | - $current_term_id = get_queried_object_id(); |
|
367 | - $current_taxonomy = get_query_var('taxonomy'); |
|
368 | - $current_posttype = geodir_get_current_posttype(); |
|
369 | - |
|
370 | - if ($current_term_id && $current_posttype && get_query_var('taxonomy') == $current_posttype . 'category') { |
|
371 | - $is_category = true; |
|
372 | - } |
|
373 | - } |
|
374 | - } |
|
375 | - } |
|
376 | - } |
|
377 | - |
|
378 | - $parent_category = 0; |
|
379 | - if (($is_listing || $is_detail) && $cpt_filter) { |
|
380 | - $post_type_arr = array($current_posttype); |
|
381 | - } |
|
382 | - |
|
383 | - $post_types = array(); |
|
384 | - if (!empty($post_type_arr)) { |
|
385 | - if (in_array('0', $post_type_arr)) { |
|
386 | - $post_types = $gd_post_types; |
|
387 | - } else { |
|
388 | - foreach ($post_type_arr as $cpt) { |
|
389 | - if (isset($gd_post_types[$cpt])) { |
|
390 | - $post_types[$cpt] = $gd_post_types[$cpt]; |
|
391 | - } |
|
392 | - } |
|
393 | - } |
|
394 | - } |
|
395 | - |
|
396 | - if (empty($post_type_arr)) { |
|
397 | - $post_types = $gd_post_types; |
|
398 | - } |
|
399 | - |
|
400 | - $hide_empty = !empty($args['hide_empty']) ? true : false; |
|
401 | - $max_count = strip_tags($args['max_count']); |
|
402 | - $all_childs = $max_count == 'all' ? true : false; |
|
403 | - $max_count = $max_count > 0 ? (int)$max_count : 0; |
|
404 | - $max_level = strip_tags($args['max_level']); |
|
405 | - $show_count = !empty($args['show_count']) ? true : false; |
|
406 | - $hide_icon = !empty($args['hide_icon']) ? true : false; |
|
407 | - $cpt_left = !empty($args['cpt_left']) ? true : false; |
|
408 | - |
|
409 | - if(!$cpt_left){ |
|
410 | - $cpt_left = "gd-cpt-flat"; |
|
411 | - }else{ |
|
412 | - $cpt_left = ''; |
|
413 | - } |
|
414 | - |
|
415 | - $orderby = 'count'; |
|
416 | - $order = 'DESC'; |
|
417 | - if ($sort_by == 'az') { |
|
418 | - $orderby = 'name'; |
|
419 | - $order = 'ASC'; |
|
420 | - } |
|
421 | - |
|
422 | - $output = ''; |
|
423 | - if (!empty($post_types)) { |
|
424 | - foreach ($post_types as $cpt => $cpt_info) { |
|
425 | - $parent_category = ($is_category && $cat_filter && $cpt == $current_posttype) ? $current_term_id : 0; |
|
426 | - $cat_taxonomy = $cpt . 'category'; |
|
427 | - $skip_childs = false; |
|
428 | - if ($cat_filter && $cpt == $current_posttype && $is_detail && $post_ID) { |
|
429 | - $skip_childs = true; |
|
430 | - $categories = get_terms($cat_taxonomy, array('orderby' => $orderby, 'order' => $order, 'hide_empty' => $hide_empty, 'object_ids' => $post_ID)); |
|
431 | - } else { |
|
432 | - $categories = get_terms($cat_taxonomy, array('orderby' => $orderby, 'order' => $order, 'hide_empty' => $hide_empty, 'parent' => $parent_category)); |
|
433 | - } |
|
434 | - |
|
435 | - if ($hide_empty) { |
|
436 | - $categories = geodir_filter_empty_terms($categories); |
|
437 | - } |
|
438 | - if ($sort_by == 'count') { |
|
439 | - $categories = geodir_sort_terms($categories, 'count'); |
|
440 | - } |
|
325 | + $args = wp_parse_args((array)$params, |
|
326 | + array( |
|
327 | + 'title' => '', |
|
328 | + 'post_type' => array(), // NULL for all |
|
329 | + 'hide_empty' => '', |
|
330 | + 'show_count' => '', |
|
331 | + 'hide_icon' => '', |
|
332 | + 'cpt_left' => '', |
|
333 | + 'sort_by' => 'count', |
|
334 | + 'max_count' => 'all', |
|
335 | + 'max_level' => '1', |
|
336 | + 'no_cpt_filter' => '', |
|
337 | + 'no_cat_filter' => '', |
|
338 | + ) |
|
339 | + ); |
|
340 | + |
|
341 | + $sort_by = isset($args['sort_by']) && in_array($args['sort_by'], array('az', 'count')) ? $args['sort_by'] : 'count'; |
|
342 | + $cpt_filter = empty($args['no_cpt_filter']) ? true : false; |
|
343 | + $cat_filter = empty($args['no_cat_filter']) ? true : false; |
|
344 | + |
|
345 | + $gd_post_types = geodir_get_posttypes('array'); |
|
346 | + |
|
347 | + $post_type_arr = !is_array($args['post_type']) ? explode(',', $args['post_type']) : $args['post_type']; |
|
348 | + $current_posttype = geodir_get_current_posttype(); |
|
349 | + |
|
350 | + $is_listing = false; |
|
351 | + $is_detail = false; |
|
352 | + $is_category = false; |
|
353 | + $post_ID = 0; |
|
354 | + $is_listing_page = geodir_is_page('listing'); |
|
355 | + $is_detail_page = geodir_is_page('detail'); |
|
356 | + if ($is_listing_page || $is_detail_page) { |
|
357 | + $current_posttype = geodir_get_current_posttype(); |
|
358 | + |
|
359 | + if ($current_posttype != '' && isset($gd_post_types[$current_posttype])) { |
|
360 | + if ($is_detail_page) { |
|
361 | + $is_detail = true; |
|
362 | + $post_ID = is_object($post) && !empty($post->ID) ? (int)$post->ID : 0; |
|
363 | + } else { |
|
364 | + $is_listing = true; |
|
365 | + if (is_tax()) { // category page |
|
366 | + $current_term_id = get_queried_object_id(); |
|
367 | + $current_taxonomy = get_query_var('taxonomy'); |
|
368 | + $current_posttype = geodir_get_current_posttype(); |
|
369 | + |
|
370 | + if ($current_term_id && $current_posttype && get_query_var('taxonomy') == $current_posttype . 'category') { |
|
371 | + $is_category = true; |
|
372 | + } |
|
373 | + } |
|
374 | + } |
|
375 | + } |
|
376 | + } |
|
377 | + |
|
378 | + $parent_category = 0; |
|
379 | + if (($is_listing || $is_detail) && $cpt_filter) { |
|
380 | + $post_type_arr = array($current_posttype); |
|
381 | + } |
|
382 | + |
|
383 | + $post_types = array(); |
|
384 | + if (!empty($post_type_arr)) { |
|
385 | + if (in_array('0', $post_type_arr)) { |
|
386 | + $post_types = $gd_post_types; |
|
387 | + } else { |
|
388 | + foreach ($post_type_arr as $cpt) { |
|
389 | + if (isset($gd_post_types[$cpt])) { |
|
390 | + $post_types[$cpt] = $gd_post_types[$cpt]; |
|
391 | + } |
|
392 | + } |
|
393 | + } |
|
394 | + } |
|
395 | + |
|
396 | + if (empty($post_type_arr)) { |
|
397 | + $post_types = $gd_post_types; |
|
398 | + } |
|
399 | + |
|
400 | + $hide_empty = !empty($args['hide_empty']) ? true : false; |
|
401 | + $max_count = strip_tags($args['max_count']); |
|
402 | + $all_childs = $max_count == 'all' ? true : false; |
|
403 | + $max_count = $max_count > 0 ? (int)$max_count : 0; |
|
404 | + $max_level = strip_tags($args['max_level']); |
|
405 | + $show_count = !empty($args['show_count']) ? true : false; |
|
406 | + $hide_icon = !empty($args['hide_icon']) ? true : false; |
|
407 | + $cpt_left = !empty($args['cpt_left']) ? true : false; |
|
408 | + |
|
409 | + if(!$cpt_left){ |
|
410 | + $cpt_left = "gd-cpt-flat"; |
|
411 | + }else{ |
|
412 | + $cpt_left = ''; |
|
413 | + } |
|
414 | + |
|
415 | + $orderby = 'count'; |
|
416 | + $order = 'DESC'; |
|
417 | + if ($sort_by == 'az') { |
|
418 | + $orderby = 'name'; |
|
419 | + $order = 'ASC'; |
|
420 | + } |
|
421 | + |
|
422 | + $output = ''; |
|
423 | + if (!empty($post_types)) { |
|
424 | + foreach ($post_types as $cpt => $cpt_info) { |
|
425 | + $parent_category = ($is_category && $cat_filter && $cpt == $current_posttype) ? $current_term_id : 0; |
|
426 | + $cat_taxonomy = $cpt . 'category'; |
|
427 | + $skip_childs = false; |
|
428 | + if ($cat_filter && $cpt == $current_posttype && $is_detail && $post_ID) { |
|
429 | + $skip_childs = true; |
|
430 | + $categories = get_terms($cat_taxonomy, array('orderby' => $orderby, 'order' => $order, 'hide_empty' => $hide_empty, 'object_ids' => $post_ID)); |
|
431 | + } else { |
|
432 | + $categories = get_terms($cat_taxonomy, array('orderby' => $orderby, 'order' => $order, 'hide_empty' => $hide_empty, 'parent' => $parent_category)); |
|
433 | + } |
|
434 | + |
|
435 | + if ($hide_empty) { |
|
436 | + $categories = geodir_filter_empty_terms($categories); |
|
437 | + } |
|
438 | + if ($sort_by == 'count') { |
|
439 | + $categories = geodir_sort_terms($categories, 'count'); |
|
440 | + } |
|
441 | 441 | |
442 | - $categories = apply_filters('geodir_custom_sort_cpt_terms', $categories); |
|
443 | - |
|
444 | - if (!empty($categories)) { |
|
445 | - $term_icons = !$hide_icon ? geodir_get_term_icon() : array(); |
|
446 | - $row_class = ''; |
|
447 | - |
|
448 | - if ($is_listing) { |
|
449 | - $row_class = $is_category ? ' gd-cptcat-categ' : ' gd-cptcat-listing'; |
|
450 | - } |
|
451 | - $cpt_row = '<div class="gd-cptcat-row gd-cptcat-' . $cpt . $row_class . ' '.$cpt_left.'">'; |
|
452 | - |
|
453 | - if ($is_category && $cat_filter && $cpt == $current_posttype) { |
|
454 | - $term_info = get_term($current_term_id, $cat_taxonomy); |
|
455 | - |
|
456 | - $term_icon_url = !empty($term_icons) && isset($term_icons[$term_info->term_id]) ? $term_icons[$term_info->term_id] : ''; |
|
457 | - $term_icon_url = $term_icon_url != '' ? '<img alt="' . esc_attr($term_info->name) . ' icon" src="' . $term_icon_url . '" /> ' : ''; |
|
458 | - |
|
459 | - $count = $show_count ? ' <span class="gd-cptcat-count">(' . $term_info->count . ')</span>' : ''; |
|
460 | - $cpt_row .= '<h2 class="gd-cptcat-title">' . $term_icon_url . $term_info->name . $count . '</h2>'; |
|
461 | - } else { |
|
462 | - $cpt_row .= '<h2 class="gd-cptcat-title">' . __($cpt_info['labels']['name'], 'geodirectory') . '</h2>'; |
|
463 | - } |
|
464 | - foreach ($categories as $category) { |
|
465 | - $term_icon_url = !empty($term_icons) && isset($term_icons[$category->term_id]) ? $term_icons[$category->term_id] : ''; |
|
466 | - $term_icon_url = $term_icon_url != '' ? '<img alt="' . esc_attr($category->name) . ' icon" src="' . $term_icon_url . '" /> ' : ''; |
|
467 | - |
|
468 | - $term_link = get_term_link( $category, $category->taxonomy ); |
|
469 | - /** Filter documented in geodirectory-functions/general_functions.php **/ |
|
470 | - $term_link = apply_filters( 'geodir_category_term_link', $term_link, $category->term_id, $cpt ); |
|
471 | - |
|
472 | - $cpt_row .= '<ul class="gd-cptcat-ul gd-cptcat-parent '.$cpt_left.'">'; |
|
473 | - $cpt_row .= '<li class="gd-cptcat-li gd-cptcat-li-main">'; |
|
474 | - $count = $show_count ? ' <span class="gd-cptcat-count">(' . $category->count . ')</span>' : ''; |
|
475 | - $cpt_row .= '<h3 class="gd-cptcat-cat"><a href="' . esc_url($term_link) . '" title="' . esc_attr($category->name) . '">' .$term_icon_url . $category->name . $count . '</a></h3>'; |
|
476 | - if (!$skip_childs && ($all_childs || $max_count > 0) && ($max_level == 'all' || (int)$max_level > 0)) { |
|
477 | - $cpt_row .= geodir_cpt_categories_child_cats($category->term_id, $cpt, $hide_empty, $show_count, $sort_by, $max_count, $max_level, $term_icons); |
|
478 | - } |
|
479 | - $cpt_row .= '</li>'; |
|
480 | - $cpt_row .= '</ul>'; |
|
481 | - } |
|
482 | - $cpt_row .= '</div>'; |
|
483 | - |
|
484 | - $output .= $cpt_row; |
|
485 | - } |
|
486 | - } |
|
487 | - } |
|
442 | + $categories = apply_filters('geodir_custom_sort_cpt_terms', $categories); |
|
443 | + |
|
444 | + if (!empty($categories)) { |
|
445 | + $term_icons = !$hide_icon ? geodir_get_term_icon() : array(); |
|
446 | + $row_class = ''; |
|
447 | + |
|
448 | + if ($is_listing) { |
|
449 | + $row_class = $is_category ? ' gd-cptcat-categ' : ' gd-cptcat-listing'; |
|
450 | + } |
|
451 | + $cpt_row = '<div class="gd-cptcat-row gd-cptcat-' . $cpt . $row_class . ' '.$cpt_left.'">'; |
|
452 | + |
|
453 | + if ($is_category && $cat_filter && $cpt == $current_posttype) { |
|
454 | + $term_info = get_term($current_term_id, $cat_taxonomy); |
|
455 | + |
|
456 | + $term_icon_url = !empty($term_icons) && isset($term_icons[$term_info->term_id]) ? $term_icons[$term_info->term_id] : ''; |
|
457 | + $term_icon_url = $term_icon_url != '' ? '<img alt="' . esc_attr($term_info->name) . ' icon" src="' . $term_icon_url . '" /> ' : ''; |
|
458 | + |
|
459 | + $count = $show_count ? ' <span class="gd-cptcat-count">(' . $term_info->count . ')</span>' : ''; |
|
460 | + $cpt_row .= '<h2 class="gd-cptcat-title">' . $term_icon_url . $term_info->name . $count . '</h2>'; |
|
461 | + } else { |
|
462 | + $cpt_row .= '<h2 class="gd-cptcat-title">' . __($cpt_info['labels']['name'], 'geodirectory') . '</h2>'; |
|
463 | + } |
|
464 | + foreach ($categories as $category) { |
|
465 | + $term_icon_url = !empty($term_icons) && isset($term_icons[$category->term_id]) ? $term_icons[$category->term_id] : ''; |
|
466 | + $term_icon_url = $term_icon_url != '' ? '<img alt="' . esc_attr($category->name) . ' icon" src="' . $term_icon_url . '" /> ' : ''; |
|
467 | + |
|
468 | + $term_link = get_term_link( $category, $category->taxonomy ); |
|
469 | + /** Filter documented in geodirectory-functions/general_functions.php **/ |
|
470 | + $term_link = apply_filters( 'geodir_category_term_link', $term_link, $category->term_id, $cpt ); |
|
471 | + |
|
472 | + $cpt_row .= '<ul class="gd-cptcat-ul gd-cptcat-parent '.$cpt_left.'">'; |
|
473 | + $cpt_row .= '<li class="gd-cptcat-li gd-cptcat-li-main">'; |
|
474 | + $count = $show_count ? ' <span class="gd-cptcat-count">(' . $category->count . ')</span>' : ''; |
|
475 | + $cpt_row .= '<h3 class="gd-cptcat-cat"><a href="' . esc_url($term_link) . '" title="' . esc_attr($category->name) . '">' .$term_icon_url . $category->name . $count . '</a></h3>'; |
|
476 | + if (!$skip_childs && ($all_childs || $max_count > 0) && ($max_level == 'all' || (int)$max_level > 0)) { |
|
477 | + $cpt_row .= geodir_cpt_categories_child_cats($category->term_id, $cpt, $hide_empty, $show_count, $sort_by, $max_count, $max_level, $term_icons); |
|
478 | + } |
|
479 | + $cpt_row .= '</li>'; |
|
480 | + $cpt_row .= '</ul>'; |
|
481 | + } |
|
482 | + $cpt_row .= '</div>'; |
|
483 | + |
|
484 | + $output .= $cpt_row; |
|
485 | + } |
|
486 | + } |
|
487 | + } |
|
488 | 488 | |
489 | - $gd_use_query_vars = $old_gd_use_query_vars; |
|
489 | + $gd_use_query_vars = $old_gd_use_query_vars; |
|
490 | 490 | |
491 | - return $output; |
|
491 | + return $output; |
|
492 | 492 | } |
493 | 493 | |
494 | 494 | /** |
@@ -508,48 +508,48 @@ discard block |
||
508 | 508 | * @return string Html content. |
509 | 509 | */ |
510 | 510 | function geodir_cpt_categories_child_cats($parent_id, $cpt, $hide_empty, $show_count, $sort_by, $max_count, $max_level, $term_icons, $depth = 1) { |
511 | - $cat_taxonomy = $cpt . 'category'; |
|
512 | - |
|
513 | - $orderby = 'count'; |
|
514 | - $order = 'DESC'; |
|
515 | - if ($sort_by == 'az') { |
|
516 | - $orderby = 'name'; |
|
517 | - $order = 'ASC'; |
|
518 | - } |
|
519 | - |
|
520 | - if ($max_level != 'all' && $depth > (int)$max_level ) { |
|
521 | - return ''; |
|
522 | - } |
|
523 | - |
|
524 | - $child_cats = get_terms($cat_taxonomy, array('orderby' => $orderby, 'order' => $order, 'hide_empty' => $hide_empty, 'parent' => $parent_id, 'number' => $max_count)); |
|
525 | - if ($hide_empty) { |
|
526 | - $child_cats = geodir_filter_empty_terms($child_cats); |
|
527 | - } |
|
528 | - |
|
529 | - if (empty($child_cats)) { |
|
530 | - return ''; |
|
531 | - } |
|
532 | - |
|
533 | - if ($sort_by == 'count') { |
|
534 | - $child_cats = geodir_sort_terms($child_cats, 'count'); |
|
535 | - } |
|
536 | - |
|
537 | - $content = '<li class="gd-cptcat-li gd-cptcat-li-sub"><ul class="gd-cptcat-ul gd-cptcat-sub gd-cptcat-sub-' . $depth . '">'; |
|
538 | - $depth++; |
|
539 | - foreach ($child_cats as $category) { |
|
540 | - $term_icon_url = !empty($term_icons) && isset($term_icons[$category->term_id]) ? $term_icons[$category->term_id] : ''; |
|
541 | - $term_icon_url = $term_icon_url != '' ? '<img alt="' . esc_attr($category->name) . ' icon" src="' . $term_icon_url . '" /> ' : ''; |
|
542 | - $term_link = get_term_link( $category, $category->taxonomy ); |
|
543 | - /** Filter documented in geodirectory-functions/general_functions.php **/ |
|
544 | - $term_link = apply_filters( 'geodir_category_term_link', $term_link, $category->term_id, $cpt ); |
|
545 | - $count = $show_count ? ' <span class="gd-cptcat-count">(' . $category->count . ')</span>' : ''; |
|
546 | - |
|
547 | - $content .= '<li class="gd-cptcat-li gd-cptcat-li-sub">'; |
|
548 | - $content .= '<a href="' . esc_url($term_link) . '" title="' . esc_attr($category->name) . '">' . $term_icon_url . $category->name . $count . '</a></li>'; |
|
549 | - $content .= geodir_cpt_categories_child_cats($category->term_id, $cpt, $hide_empty, $show_count, $sort_by, $max_count, $max_level, $term_icons, $depth); |
|
550 | - } |
|
551 | - $content .= '</li></ul>'; |
|
552 | - |
|
553 | - return $content; |
|
511 | + $cat_taxonomy = $cpt . 'category'; |
|
512 | + |
|
513 | + $orderby = 'count'; |
|
514 | + $order = 'DESC'; |
|
515 | + if ($sort_by == 'az') { |
|
516 | + $orderby = 'name'; |
|
517 | + $order = 'ASC'; |
|
518 | + } |
|
519 | + |
|
520 | + if ($max_level != 'all' && $depth > (int)$max_level ) { |
|
521 | + return ''; |
|
522 | + } |
|
523 | + |
|
524 | + $child_cats = get_terms($cat_taxonomy, array('orderby' => $orderby, 'order' => $order, 'hide_empty' => $hide_empty, 'parent' => $parent_id, 'number' => $max_count)); |
|
525 | + if ($hide_empty) { |
|
526 | + $child_cats = geodir_filter_empty_terms($child_cats); |
|
527 | + } |
|
528 | + |
|
529 | + if (empty($child_cats)) { |
|
530 | + return ''; |
|
531 | + } |
|
532 | + |
|
533 | + if ($sort_by == 'count') { |
|
534 | + $child_cats = geodir_sort_terms($child_cats, 'count'); |
|
535 | + } |
|
536 | + |
|
537 | + $content = '<li class="gd-cptcat-li gd-cptcat-li-sub"><ul class="gd-cptcat-ul gd-cptcat-sub gd-cptcat-sub-' . $depth . '">'; |
|
538 | + $depth++; |
|
539 | + foreach ($child_cats as $category) { |
|
540 | + $term_icon_url = !empty($term_icons) && isset($term_icons[$category->term_id]) ? $term_icons[$category->term_id] : ''; |
|
541 | + $term_icon_url = $term_icon_url != '' ? '<img alt="' . esc_attr($category->name) . ' icon" src="' . $term_icon_url . '" /> ' : ''; |
|
542 | + $term_link = get_term_link( $category, $category->taxonomy ); |
|
543 | + /** Filter documented in geodirectory-functions/general_functions.php **/ |
|
544 | + $term_link = apply_filters( 'geodir_category_term_link', $term_link, $category->term_id, $cpt ); |
|
545 | + $count = $show_count ? ' <span class="gd-cptcat-count">(' . $category->count . ')</span>' : ''; |
|
546 | + |
|
547 | + $content .= '<li class="gd-cptcat-li gd-cptcat-li-sub">'; |
|
548 | + $content .= '<a href="' . esc_url($term_link) . '" title="' . esc_attr($category->name) . '">' . $term_icon_url . $category->name . $count . '</a></li>'; |
|
549 | + $content .= geodir_cpt_categories_child_cats($category->term_id, $cpt, $hide_empty, $show_count, $sort_by, $max_count, $max_level, $term_icons, $depth); |
|
550 | + } |
|
551 | + $content .= '</li></ul>'; |
|
552 | + |
|
553 | + return $content; |
|
554 | 554 | } |
555 | 555 | ?> |
556 | 556 | \ No newline at end of file |