PluginProbe
BetterDocs – AI Documentation, Knowledge Base, MCP Server, Docs, Wikis, FAQ & Chatbot / 4.9.2
BetterDocs – AI Documentation, Knowledge Base, MCP Server, Docs, Wikis, FAQ & Chatbot v4.9.2
4.9.2 4.9.1 4.9.0 4.8.2 4.8.1 4.8.0 4.7.0 4.6.2 4.6.1 4.6.0 4.5.6 4.5.5 4.5.4 4.5.3 4.5.2 4.5.1 4.5.0 4.4.1 4.4.0 3.3.4 3.4.0 3.4.1 3.4.2 3.5.0 3.5.1 All 200 releases
betterdocs / includes / Editors / Elementor / Widget / CategoryArchiveHeader.php

CategoryArchiveHeader.php in BetterDocs – AI Documentation, Knowledge Base, MCP Server, Docs, Wikis, FAQ & Chatbot 4.9.2, at includes/Editors/Elementor/Widget/CategoryArchiveHeader.php

360 lines 10.4 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 namespace WPDeveloper\BetterDocs\Editors\Elementor\Widget;
4
5 if ( ! defined( 'ABSPATH' ) ) {
6 exit; // Exit if accessed directly
7 }
8
9 use Elementor\Plugin;
10 use Elementor\Controls_Manager;
11 use Elementor\Group_Control_Background;
12 use Elementor\Group_Control_Typography;
13 use WPDeveloper\BetterDocs\Editors\Elementor\BaseWidget;
14 use WP_Query;
15
16 class CategoryArchiveHeader extends BaseWidget {
17 public function get_name() {
18 return 'doc-category-archive-header';
19 }
20
21 public function get_title() {
22 return __( 'Doc Category Archive Header', 'betterdocs' );
23 }
24
25 public function get_icon() {
26 return 'betterdocs-icon-archive-header';
27 }
28
29 public function get_keywords() {
30 return [ 'betterdocs-elements', 'archive', 'docs', 'betterdocs', 'archive-header', 'doc-archive-header' ];
31 }
32
33 public function get_custom_help_url() {
34 return 'https://betterdocs.co/docs/single-doc-in-elementor';
35 }
36
37 public function get_categories() {
38 return [ 'betterdocs-elements', 'docs-archive' ];
39 }
40
41 public function get_style_depends() {
42 return [
43 'betterdocs-category-archive-header'
44 ];
45 }
46
47 protected function register_controls() {
48 $this->start_controls_section(
49 'section_betterdocs_category_archive_header_general_settings',
50 [
51 'label' => __( 'General', 'betterdocs' )
52 ]
53 );
54
55 $this->add_control(
56 'section_betterdocs_category_archive_header_title_tag',
57 [
58 'label' => __( 'Select Tag', 'betterdocs' ),
59 'type' => Controls_Manager::SELECT,
60 'default' => 'h2',
61 'options' => [
62 'h1' => __( 'H1', 'betterdocs' ),
63 'h2' => __( 'H2', 'betterdocs' ),
64 'h3' => __( 'H3', 'betterdocs' ),
65 'h4' => __( 'H4', 'betterdocs' ),
66 'h5' => __( 'H5', 'betterdocs' ),
67 'h6' => __( 'H6', 'betterdocs' ),
68 'span' => __( 'Span', 'betterdocs' ),
69 'p' => __( 'P', 'betterdocs' ),
70 'div' => __( 'Div', 'betterdocs' )
71 ]
72 ]
73 );
74
75 $this->add_control(
76 'section_betterdocs_category_archive_header_show_icon',
77 [
78 'label' => __( 'Show Icon', 'betterdocs' ),
79 'type' => Controls_Manager::SWITCHER,
80 'label_on' => __( 'Show', 'betterdocs' ),
81 'label_off' => __( 'Hide', 'betterdocs' ),
82 'return_value' => 'true',
83 'default' => 'true'
84 ]
85 );
86
87 $this->add_control(
88 'section_betterdocs_category_archive_header_show_count',
89 [
90 'label' => __( 'Show Count', 'betterdocs' ),
91 'type' => Controls_Manager::SWITCHER,
92 'label_on' => __( 'Show', 'betterdocs' ),
93 'label_off' => __( 'Hide', 'betterdocs' ),
94 'return_value' => 'true',
95 'default' => 'true'
96 ]
97 );
98
99 $this->end_controls_section();
100
101 $this->wrapper_header();
102 $this->archive_title();
103 $this->archive_icon();
104 $this->archive_count();
105 }
106
107 public function wrapper_header() {
108 $this->start_controls_section(
109 'section_betterdocs_category_archive_wrapper_header',
110 [
111 'label' => __( 'Header Wrapper', 'betterdocs' ),
112 'tab' => Controls_Manager::TAB_STYLE
113 ]
114 );
115
116 $this->add_group_control(
117 Group_Control_Background::get_type(),
118 [
119 'name' => 'section_betterdocs_category_archive_header_color',
120 'types' => [ 'classic', 'gradient' ],
121 'label' => esc_html__( 'Background Color', 'betterdocs' ),
122 'selector' => '{{WRAPPER}} .betterdocs-main-category-folder'
123 ]
124 );
125
126 $this->add_group_control(
127 Group_Control_Background::get_type(),
128 [
129 'name' => 'section_betterdocs_category_archive_header_hover_color',
130 'types' => [ 'classic', 'gradient' ],
131 'label' => esc_html__( 'Background Hover Color', 'betterdocs' ),
132 'selector' => '{{WRAPPER}} .betterdocs-main-category-folder:hover'
133 ]
134 );
135
136 $this->add_responsive_control(
137 'section_betterdocs_category_archive_header_padding',
138 [
139 'label' => __( 'Padding', 'betterdocs' ),
140 'type' => Controls_Manager::DIMENSIONS,
141 'size_units' => [ 'px', 'em', '%' ],
142 'selectors' => [
143 '{{WRAPPER}} .betterdocs-main-category-folder' => 'padding: {{TOP}}{{UNIT}} {{RIGHT}}{{UNIT}} {{BOTTOM}}{{UNIT}} {{LEFT}}{{UNIT}};'
144 ]
145 ]
146 );
147
148 $this->add_responsive_control(
149 'section_betterdocs_category_archive_header_margin',
150 [
151 'label' => __( 'Margin', 'betterdocs' ),
152 'type' => Controls_Manager::DIMENSIONS,
153 'size_units' => [ 'px', 'em', '%' ],
154 'selectors' => [
155 '{{WRAPPER}} .betterdocs-main-category-folder' => 'margin: {{TOP}}{{UNIT}} {{RIGHT}}{{UNIT}} {{BOTTOM}}{{UNIT}} {{LEFT}}{{UNIT}};'
156 ]
157 ]
158 );
159
160 $this->end_controls_section();
161 }
162
163 public function archive_title() {
164 $this->start_controls_section(
165 'section_betterdocs_category_archive_title',
166 [
167 'label' => __( 'Title', 'betterdocs' ),
168 'tab' => Controls_Manager::TAB_STYLE
169 ]
170 );
171
172 $this->add_group_control(
173 Group_Control_Typography::get_type(),
174 [
175 'name' => 'section_betterdocs_category_archive_title_typography',
176 'selector' => '{{WRAPPER}} .betterdocs-main-category-folder .betterdocs-category-header-inner .betterdocs-category-title'
177 ]
178 );
179
180 $this->add_control(
181 'section_betterdocs_category_archive_title_color',
182 [
183 'label' => esc_html__( 'Color', 'betterdocs' ),
184 'type' => Controls_Manager::COLOR,
185 'selectors' => [
186 '{{WRAPPER}} .betterdocs-main-category-folder .betterdocs-category-header-inner .betterdocs-category-title' => 'color: {{VALUE}};'
187 ]
188 ]
189 );
190
191 $this->add_control(
192 'section_betterdocs_category_archive_title_hover_color',
193 [
194 'label' => esc_html__( 'Color Hover', 'betterdocs' ),
195 'type' => Controls_Manager::COLOR,
196 'selectors' => [
197 '{{WRAPPER}} .betterdocs-main-category-folder .betterdocs-category-header-inner .betterdocs-category-title:hover' => 'color: {{VALUE}};'
198 ]
199 ]
200 );
201
202 $this->end_controls_section();
203 }
204
205 public function archive_icon() {
206 $this->start_controls_section(
207 'section_betterdocs_category_archive_icon',
208 [
209 'label' => __( 'Icon', 'betterdocs' ),
210 'tab' => Controls_Manager::TAB_STYLE
211 ]
212 );
213 $this->add_group_control(
214 Group_Control_Background::get_type(),
215 [
216 'name' => 'section_betterdocs_category_archive_icon_background',
217 'types' => [ 'classic', 'gradient' ],
218 'label' => esc_html__( 'Background Color', 'betterdocs' ),
219 'selector' => '{{WRAPPER}} .betterdocs-main-category-folder .betterdocs-category-header-inner .betterdocs-category-icon .betterdocs-folder-icon'
220 ]
221 );
222 $this->add_control(
223 'section_betterdocs_category_archive_icon_size',
224 [
225 'label' => __( 'Icon Size', 'betterdocs' ),
226 'type' => Controls_Manager::SLIDER,
227 'size_units' => [ 'px', 'em' ],
228 'range' => [
229 'px' => [
230 'min' => 0,
231 'max' => 1000
232 ]
233 ],
234 'selectors' => [
235 '{{WRAPPER}} .betterdocs-main-category-folder .betterdocs-category-header-inner .betterdocs-category-icon .betterdocs-folder-icon' => 'height:{{SIZE}}{{UNIT}}; width:{{SIZE}}{{UNIT}};'
236 ]
237 ]
238 );
239 $this->end_controls_section();
240 }
241
242 public function archive_count() {
243 $this->start_controls_section(
244 'section_betterdocs_category_archive_count',
245 [
246 'label' => __( 'Count', 'betterdocs' ),
247 'tab' => Controls_Manager::TAB_STYLE
248 ]
249 );
250
251 $this->add_group_control(
252 Group_Control_Typography::get_type(),
253 [
254 'name' => 'section_betterdocs_category_archive_count_typography',
255 'selector' => '{{WRAPPER}} .betterdocs-main-category-folder .betterdocs-category-header-inner .betterdocs-sub-category-items-counts'
256 ]
257 );
258
259 $this->add_control(
260 'section_betterdocs_category_archive_count_color',
261 [
262 'label' => esc_html__( 'Color', 'betterdocs' ),
263 'type' => Controls_Manager::COLOR,
264 'selectors' => [
265 '{{WRAPPER}} .betterdocs-main-category-folder .betterdocs-category-header-inner .betterdocs-sub-category-items-counts' => 'color: {{VALUE}};'
266 ]
267 ]
268 );
269
270 $this->add_control(
271 'section_betterdocs_category_archive_count_hover_color',
272 [
273 'label' => esc_html__( 'Color Hover', 'betterdocs' ),
274 'type' => Controls_Manager::COLOR,
275 'selectors' => [
276 '{{WRAPPER}} .betterdocs-main-category-folder .betterdocs-category-header-inner .betterdocs-sub-category-items-counts:hover' => 'color: {{VALUE}};'
277 ]
278 ]
279 );
280
281 $this->end_controls_section();
282 }
283
284 public function view_params() {
285 $settings = &$this->attributes;
286 $settings['taxonomy'] = 'doc_category';
287
288 // Check if Elementor is in editor mode
289 if ( Plugin::instance()->editor->is_edit_mode() ) {
290 // Fallback: Get the doc_category with the highest assigned posts in editor mode
291 $args = [
292 'taxonomy' => 'doc_category',
293 'orderby' => 'count',
294 'order' => 'DESC',
295 'hide_empty' => false,
296 'number' => 1 // Only get the top category
297 ];
298 $categories = get_terms( $args );
299 $current_category = ! empty( $categories ) ? $categories[0] : null;
300 } else {
301 $current_category = get_queried_object();
302 }
303
304 if ( ! $current_category ) {
305 return [];
306 }
307
308 // Ensure we have a term object, not a post type object
309 if ( ! isset( $current_category->term_id ) || ! isset( $current_category->slug ) ) {
310 // If it's not a term object, try to get the first category as fallback
311 $args = [
312 'taxonomy' => 'doc_category',
313 'orderby' => 'count',
314 'order' => 'DESC',
315 'hide_empty' => false,
316 'number' => 1
317 ];
318 $categories = get_terms( $args );
319 $current_category = ! empty( $categories ) ? $categories[0] : null;
320
321 if ( ! $current_category ) {
322 return [];
323 }
324 }
325
326 $args = betterdocs()->query->docs_query_args(
327 [
328 'term_id' => $current_category->term_id,
329 'term_slug' => $current_category->slug,
330 'posts_per_page' => -1
331 ]
332 );
333
334 $post_query = new WP_Query( $args );
335
336 $_nested_categories = betterdocs()->query->get_child_term_ids_by_parent_id( 'doc_category', $current_category->term_id );
337
338 if ( $_nested_categories ) {
339 $sub_terms_count = count( explode( ',', $_nested_categories ) );
340 } else {
341 $sub_terms_count = 0;
342 }
343
344 $params = [
345 'current_category' => $current_category,
346 'found_posts' => $post_query->found_posts,
347 'sub_terms_count' => $sub_terms_count,
348 'show_icon' => $settings['section_betterdocs_category_archive_header_show_icon'],
349 'title_tag' => $settings['section_betterdocs_category_archive_header_title_tag'],
350 'show_count' => $settings['section_betterdocs_category_archive_header_show_count']
351 ];
352
353 return $params;
354 }
355
356 public function render_callback() {
357 $this->views( 'template-parts/archive-header' );
358 }
359 }
360