PluginProbe
BetterDocs – AI Documentation, Knowledge Base, MCP Server, Docs, Wikis, FAQ & Chatbot / 4.9.3
BetterDocs – AI Documentation, Knowledge Base, MCP Server, Docs, Wikis, FAQ & Chatbot v4.9.3
4.9.3 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 All 201 releases
betterdocs / views / template-parts / category-list.php

category-list.php in BetterDocs – AI Documentation, Knowledge Base, MCP Server, Docs, Wikis, FAQ & Chatbot 4.9.3, at views/template-parts/category-list.php

166 lines 7.2 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 // phpcs:disable WordPress.NamingConventions.PrefixAllGlobals.NonPrefixedVariableFound -- view template receives variables via extract(); prefixing is impractical.
3
4 if ( ! defined( 'ABSPATH' ) ) {
5 exit;
6 }
7 use WPDeveloper\BetterDocs\Utils\Helper;
8
9 $posts = betterdocs()->query->get_posts( $query_args, true );
10
11 if ( ! $posts->have_posts() ) {
12 wp_reset_postdata();
13 }
14
15 $_page_id = null;
16
17 if ( is_single() ) {
18 $_page_id = get_the_ID();
19 }
20
21 // if there have list icon url from settings or customizer or shortcodes attribites format it to $list_icon_name
22 $settings_list_icon = betterdocs()->settings->get( 'docs_list_icon' );
23
24 // Ensure $layout_type is set
25 if ( ! isset( $layout_type ) ) {
26 $layout_type = '';
27 }
28
29 // Ensure $list_icon_url is set
30 if ( ! isset( $list_icon_url ) ) {
31 $list_icon_url = '';
32 }
33
34 // Ensure $list_icon_name is always initialized as an array to prevent TypeError
35 if ( ! isset( $list_icon_name ) || ! is_array( $list_icon_name ) ) {
36 $list_icon_name = array();
37 }
38
39 #for elementor if icon is not selected from settings, and icon attributes are empty, then look for settings, if settings is empty show default icon, else show from settings. If svg from list is selected, then show svg, else show from settings, if settings is empty then show default. Not applicable for sidebar layout-2 elementor
40 if ( isset( $layout_type ) && 'widget' == $layout_type ) {
41 if ( isset( $sidebar_layout ) && 'layout-2' == $sidebar_layout ) { #done to avoid warning for elementor sidebar layout-2
42 $list_icon_name = array();
43 }
44
45 // Ensure $list_icon_name is an array before using array_key_exists
46 if ( ! is_array( $list_icon_name ) ) {
47 $list_icon_name = array();
48 }
49
50 $list_icon_name = ( array_key_exists( 'value', $list_icon_name ) && array_key_exists( 'library', $list_icon_name ) || array_key_exists( 'value', $list_icon_name ) ) ? ( empty( $list_icon_name[ 'value' ] ) && empty( $list_icon_name[ 'library' ] ) || empty( $list_icon_name[ 'value' ] ) ? ( isset( $settings_list_icon[ 'url' ] ) ? array( 'value' => array( 'url' => $settings_list_icon[ 'url' ] ) ) : array() ) : $list_icon_name ) : ( isset( $list_icon_name[ 'url' ] ) ? array( 'value' => array( 'url' => $list_icon_name[ 'url' ] ) ) : ( isset( $settings_list_icon[ 'url' ] ) ? $settings_list_icon[ 'url' ] : array() ) );
51 }
52
53 // #for blocks if $list_icon_name is empty, but for category grid block
54 if ( isset( $layout_type ) && 'block' == $layout_type ) {
55 if ( empty( $list_icon_name ) && isset( $widget_type ) && 'category-grid' == $widget_type ) {
56 $list_icon_name = array(
57 'value'
58 );
59 }
60 }
61
62 #for blocks if $sidebar_layout is passed, then remove the list icon for layout-4
63 if ( isset( $layout_type ) && 'block' == $layout_type ) {
64 if ( isset( $sidebar_layout ) && 'layout-4' == $sidebar_layout ) {
65 $list_icon_name = array(
66 'value' => array(
67 'url' => 'list'
68 )
69 );
70 }
71 }
72
73 if ( isset( $layout_type ) && ! empty( $layout_type ) && 'template' == $layout_type && isset( $list_icon_url ) && $list_icon_url ) {
74 if ( isset( $list_icon_url ) && $list_icon_url ) {
75 $list_icon_name = array(
76 'value' => array(
77 'url' => $list_icon_url
78 )
79 );
80 }
81 }
82 ?>
83
84 <ul class="betterdocs-articles-list">
85 <?php
86 if ( '' === $query_args[ 'posts_per_page' ] ) {
87 $query_args[ 'posts_per_page' ] = get_option( 'posts_per_page' );
88 }
89
90 if ( -1 == $query_args[ 'posts_per_page' ] || $query_args[ 'posts_per_page' ] > 0 ) {
91 $pos = 'left';
92 $icon = 'list';
93 $show_icon = true;
94
95 // Check if list icon should be shown
96 if ( isset( $show_list_icon ) && false === $show_list_icon ) {
97 $show_icon = false;
98 }
99
100 if ( ! empty( $list_icon_position ) ) {
101 if ( 'right' == $list_icon_position ) {
102 $pos = 'right';
103 }
104 }
105 if ( ! empty( $list_icon_name ) ) {
106 $icon = $list_icon_name;
107 }
108 while ( $posts->have_posts() ):
109 $posts->the_post();
110 $_link_attributes = array(
111 'href' => esc_url( get_the_permalink() )
112 );
113
114 if ( get_the_ID() === $_page_id && Helper::get_tax() != 'doc_category' ) {
115 $_link_attributes[ 'class' ] = 'active';
116 }
117
118 $_link_attributes = betterdocs()->template_helper->get_html_attributes( $_link_attributes );
119
120 echo wp_sprintf(
121 '<li>%4$s<a %1$s><span>%2$s</span> %3$s</a></li>',
122 $_link_attributes, // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
123 /**
124 * Filter a doc item's title markup in category/sidebar doc
125 * lists (e.g. to prepend an API method badge). Deliberately
126 * NOT core `the_title` — this must stay scoped to list items.
127 *
128 * SECURITY CONTRACT: the return value is echoed as HTML and
129 * is NOT escaped afterwards — it has to be, or a callback
130 * could not add the markup this filter exists for. The value
131 * passed in is already kses'd; a callback that wraps or
132 * appends to it is responsible for escaping whatever IT
133 * introduces. Never hand this filter unsanitised user input.
134 *
135 * @param string $title_html Kses'd title markup.
136 * @param int $post_id
137 */
138 apply_filters( 'betterdocs_docs_list_item_title', betterdocs()->template_helper->kses( get_the_title() ), get_the_ID() ), // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
139 ( $show_icon && 'right' == $pos ) ? betterdocs()->template_helper->icon( $icon ) : '', // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
140 ( $show_icon && 'left' == $pos ) ? betterdocs()->template_helper->icon( $icon ) : '' // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
141 );
142 endwhile;
143
144 wp_reset_postdata();
145 }
146 /**
147 * Nested Sub Categories
148 */
149 if ( (bool) $nested_subcategory && $term instanceof \WP_Term ) {
150 $_params = get_defined_vars();
151 $_params = isset( $_params[ 'params' ] ) ? $_params[ 'params' ] : array();
152 $_params = wp_parse_args(
153 array(
154 'term_id' => $term->term_id,
155 'list_icon_url' => $list_icon_url
156 ),
157 $_params
158 );
159 if ( 'widget' == $layout_type || 'block' == $layout_type ) {
160 $_params[ 'list_icon_name' ] = $list_icon_name;
161 }
162 $view_object->get( 'template-parts/nested-categories', $_params );
163 }
164 ?>
165 </ul>
166