PluginProbe
BetterDocs – AI Documentation, Knowledge Base, MCP Server, Docs, Wikis, FAQ & Chatbot / 4.1.2
BetterDocs – AI Documentation, Knowledge Base, MCP Server, Docs, Wikis, FAQ & Chatbot v4.1.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 3.5.2 All 199 releases
betterdocs / includes / Shortcodes / CategoryBox.php

CategoryBox.php in BetterDocs – AI Documentation, Knowledge Base, MCP Server, Docs, Wikis, FAQ & Chatbot 4.1.2, at includes/Shortcodes/CategoryBox.php

122 lines 4.0 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\Shortcodes;
4
5 use WPDeveloper\BetterDocs\Core\Shortcode;
6
7 class CategoryBox extends Shortcode {
8 protected $layout_class = 'layout-1';
9 protected $deprecated_attributes = [
10 'category' => 'taxonomy',
11 'icon' => 'show_icon'
12 ];
13
14 public function get_name() {
15 return 'betterdocs_category_box';
16 }
17
18 public function get_style_depends() {
19 return [ 'betterdocs-category-box' ];
20 }
21
22 public function default_attributes() {
23 return [
24 'taxonomy' => 'doc_category',
25 'parent' => 0,
26 'meta_key' => '',
27 'layout' => '',
28 'column' => $this->settings->get( 'column_number', 3 ),
29 'orderby' => $this->settings->get( 'alphabetically_order_post', 'title' ),
30 'nested_subcategory' => (bool) $this->settings->get( 'nested_subcategory', false ),
31 'terms' => '',
32 'terms_order' => $this->settings->get( 'terms_order', 'ASC' ),
33 'terms_orderby' => $this->settings->get( 'terms_orderby', 'betterdocs_order' ),
34 'show_icon' => true,
35 'kb_slug' => '',
36 'title_tag' => 'h2',
37 'multiple_knowledge_base' => false,
38 'disable_customizer_style' => false,
39 'border_bottom' => false,
40 'show_description' => (bool) $this->customizer->get( 'betterdocs_doc_page_cat_desc', false )
41 ];
42 }
43
44 public function header_sequence( $_layout_sequence, $layout, $widget_type, $_defined_vars ) {
45 return [ 'category_icon', 'category_title', 'category_description', 'category_counts' ];
46 }
47
48 public function render( $atts, $content = null ) {
49 add_filter( 'betterdocs_header_layout_sequence', [ $this, 'header_sequence' ], 10, 4 );
50
51 $this->views( 'layouts/base' );
52
53 remove_filter( 'betterdocs_header_layout_sequence', [ $this, 'header_sequence' ], 10 );
54 }
55
56 public function view_params() {
57 $classes = [ 'betterdocs-category-box-inner-wrapper', $this->layout_class, ( $this->layout_class != 'layout-4' ? 'layout-flex ash-bg' : '' ) ];
58 $styles = '';
59
60 if ( $this->isset( 'column' ) ) {
61 $_c = intval( $this->attributes['column'] );
62 $classes[] = 'docs-col-' . $_c;
63 $styles .= "--column: $_c;";
64 }
65
66 if ( $this->isset( 'border_bottom', true ) ) {
67 $classes[] = 'border-bottom';
68 }
69
70 if ( $this->isset( 'disable_customizer_style', false ) ) {
71 $classes[] = 'single-kb';
72 }
73
74 $_query_args = [
75 'terms' => $this->attributes['terms'],
76 'order' => $this->attributes['terms_order'],
77 'orderby' => $this->attributes['terms_orderby'],
78 'multiple_kb' => $this->attributes['multiple_knowledge_base'],
79 'kb_slug' => $this->attributes['kb_slug'],
80 'nested_subcategory' => (bool) $this->attributes['nested_subcategory']
81 ];
82
83 if ( $this->isset( 'taxonomy' ) ) {
84 $_query_args['taxonomy'] = $this->attributes['taxonomy'];
85 }
86
87 // if ( $this->isset( 'parent', 0 ) ) {
88 // $_query_args['parent'] = $this->attributes['parent'];
89 // }
90
91 if ( $this->isset( 'meta_key' ) ) {
92 $_query_args['meta_key'] = $this->attributes['meta_key'];
93 }
94
95 $terms_query = $this->query->terms_query( $_query_args );
96
97 $show_count = (bool) $this->settings->get( 'post_count', false );
98 $singular_text = $this->settings->get( 'count_text_singular' );
99 $plural_text = $this->settings->get( 'count_text' );
100
101 $inner_wrapper_attr = [
102 'class' => $classes,
103 'style' => $styles,
104 ];
105
106 return [
107 'wrapper_attr' => [ 'class' => [ 'betterdocs-category-box-wrapper' ] ],
108 'inner_wrapper_attr' => $inner_wrapper_attr,
109 'layout' => 'default',
110 'widget_type' => 'category-box',
111
112 'terms_query_args' => $terms_query,
113
114 'show_title' => true,
115 'show_count' => $show_count,
116 'count_suffix_singular' => $singular_text,
117 'count_suffix' => $plural_text,
118 'title_tag' => $this->attributes['title_tag']
119 ];
120 }
121 }
122