| 1 |
<?php |
| 2 |
/** |
| 3 |
* Single Doc Template |
| 4 |
* |
| 5 |
* @package King_Addons |
| 6 |
*/ |
| 7 |
|
| 8 |
if (!defined('ABSPATH')) { |
| 9 |
exit; |
| 10 |
} |
| 11 |
|
| 12 |
$options = \King_Addons\Docs_KB::instance()->get_options(); |
| 13 |
$docs_kb = \King_Addons\Docs_KB::instance(); |
| 14 |
|
| 15 |
// Get current doc |
| 16 |
$doc_id = get_the_ID(); |
| 17 |
|
| 18 |
// Track view (Pro) |
| 19 |
if (!empty($options['analytics_enabled'])) { |
| 20 |
$docs_kb->track_view($doc_id); |
| 21 |
} |
| 22 |
|
| 23 |
// Get category |
| 24 |
$categories = get_the_terms($doc_id, \King_Addons\Docs_KB::TAXONOMY); |
| 25 |
$current_category = !empty($categories) ? $categories[0] : null; |
| 26 |
|
| 27 |
// Get navigation |
| 28 |
$navigation = !empty($options['navigation_enabled']) ? $docs_kb->get_article_navigation($doc_id) : null; |
| 29 |
|
| 30 |
// Get related docs (Pro) |
| 31 |
$related_docs = !empty($options['related_enabled']) ? $docs_kb->get_related_docs($doc_id, $options['related_count'] ?? 3) : []; |
| 32 |
|
| 33 |
// Settings |
| 34 |
$toc_enabled = !empty($options['toc_enabled']); |
| 35 |
$sidebar_enabled = !empty($options['sidebar_enabled']); |
| 36 |
$print_button = !empty($options['print_button']); |
| 37 |
$feedback_enabled = !empty($options['feedback_enabled']); |
| 38 |
$primary_color = $options['primary_color'] ?? '#0066ff'; |
| 39 |
|
| 40 |
get_header(); |
| 41 |
?> |
| 42 |
|
| 43 |
<div class="kng-docs-page kng-docs-single" style="--kng-docs-primary: <?php echo esc_attr($primary_color); ?>;"> |
| 44 |
<div class="kng-docs-container"> |
| 45 |
|
| 46 |
<!-- Breadcrumbs --> |
| 47 |
<nav class="kng-docs-breadcrumbs" aria-label="<?php esc_attr_e('Breadcrumb', 'king-addons'); ?>"> |
| 48 |
<a href="<?php echo esc_url(get_post_type_archive_link(\King_Addons\Docs_KB::POST_TYPE)); ?>" class="kng-docs-breadcrumb-item"> |
| 49 |
<svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2"> |
| 50 |
<path d="M3 9l9-7 9 7v11a2 2 0 01-2 2H5a2 2 0 01-2-2z"/> |
| 51 |
</svg> |
| 52 |
<?php esc_html_e('Docs', 'king-addons'); ?> |
| 53 |
</a> |
| 54 |
<?php if ($current_category): ?> |
| 55 |
<span class="kng-docs-breadcrumb-sep">/</span> |
| 56 |
<a href="<?php echo esc_url(get_term_link($current_category)); ?>" class="kng-docs-breadcrumb-item"> |
| 57 |
<?php echo esc_html($current_category->name); ?> |
| 58 |
</a> |
| 59 |
<?php endif; ?> |
| 60 |
<span class="kng-docs-breadcrumb-sep">/</span> |
| 61 |
<span class="kng-docs-breadcrumb-current"><?php the_title(); ?></span> |
| 62 |
</nav> |
| 63 |
|
| 64 |
<div class="kng-docs-single-layout <?php echo $sidebar_enabled ? 'has-sidebar' : ''; ?>"> |
| 65 |
|
| 66 |
<?php if ($sidebar_enabled): ?> |
| 67 |
<!-- Sidebar --> |
| 68 |
<aside class="kng-docs-sidebar <?php echo !empty($options['toc_sticky']) ? 'is-sticky' : ''; ?>"> |
| 69 |
<div class="kng-docs-sidebar-inner"> |
| 70 |
<?php if ($current_category): ?> |
| 71 |
<h4 class="kng-docs-sidebar-title"> |
| 72 |
<?php echo esc_html($current_category->name); ?> |
| 73 |
</h4> |
| 74 |
<?php |
| 75 |
$category_docs = get_posts([ |
| 76 |
'post_type' => \King_Addons\Docs_KB::POST_TYPE, |
| 77 |
'posts_per_page' => -1, |
| 78 |
'tax_query' => [ |
| 79 |
[ |
| 80 |
'taxonomy' => \King_Addons\Docs_KB::TAXONOMY, |
| 81 |
'field' => 'term_id', |
| 82 |
'terms' => $current_category->term_id, |
| 83 |
], |
| 84 |
], |
| 85 |
'orderby' => 'menu_order', |
| 86 |
'order' => 'ASC', |
| 87 |
]); |
| 88 |
?> |
| 89 |
<ul class="kng-docs-sidebar-list"> |
| 90 |
<?php foreach ($category_docs as $cat_doc): ?> |
| 91 |
<li class="<?php echo $cat_doc->ID === $doc_id ? 'is-current' : ''; ?>"> |
| 92 |
<a href="<?php echo esc_url(get_permalink($cat_doc)); ?>"> |
| 93 |
<?php echo esc_html($cat_doc->post_title); ?> |
| 94 |
</a> |
| 95 |
</li> |
| 96 |
<?php endforeach; ?> |
| 97 |
</ul> |
| 98 |
<?php else: ?> |
| 99 |
<!-- No category - show all categories --> |
| 100 |
<h4 class="kng-docs-sidebar-title"> |
| 101 |
<?php esc_html_e('Categories', 'king-addons'); ?> |
| 102 |
</h4> |
| 103 |
<?php |
| 104 |
$all_categories = get_terms([ |
| 105 |
'taxonomy' => \King_Addons\Docs_KB::TAXONOMY, |
| 106 |
'hide_empty' => true, |
| 107 |
'parent' => 0, |
| 108 |
]); |
| 109 |
?> |
| 110 |
<?php if (!empty($all_categories) && !is_wp_error($all_categories)): ?> |
| 111 |
<ul class="kng-docs-sidebar-list"> |
| 112 |
<?php foreach ($all_categories as $cat): ?> |
| 113 |
<li> |
| 114 |
<a href="<?php echo esc_url(get_term_link($cat)); ?>"> |
| 115 |
<?php echo esc_html($cat->name); ?> |
| 116 |
<span class="kng-docs-sidebar-count"><?php echo esc_html($cat->count); ?></span> |
| 117 |
</a> |
| 118 |
</li> |
| 119 |
<?php endforeach; ?> |
| 120 |
</ul> |
| 121 |
<?php endif; ?> |
| 122 |
<?php endif; ?> |
| 123 |
</div> |
| 124 |
</aside> |
| 125 |
<?php endif; ?> |
| 126 |
|
| 127 |
<!-- Main Content --> |
| 128 |
<article class="kng-docs-article"> |
| 129 |
<?php if ($print_button): ?> |
| 130 |
<div class="kng-docs-article-actions"> |
| 131 |
<button type="button" class="kng-docs-print-btn" onclick="window.print();"> |
| 132 |
<svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2"> |
| 133 |
<path d="M6 9V2h12v7"/> |
| 134 |
<path d="M6 18H4a2 2 0 01-2-2v-5a2 2 0 012-2h16a2 2 0 012 2v5a2 2 0 01-2 2h-2"/> |
| 135 |
<rect x="6" y="14" width="12" height="8"/> |
| 136 |
</svg> |
| 137 |
<?php esc_html_e('Print', 'king-addons'); ?> |
| 138 |
</button> |
| 139 |
</div> |
| 140 |
<?php endif; ?> |
| 141 |
|
| 142 |
<header class="kng-docs-article-header"> |
| 143 |
<h1 class="kng-docs-article-title"><?php the_title(); ?></h1> |
| 144 |
<div class="kng-docs-article-meta"> |
| 145 |
<span class="kng-docs-article-date"> |
| 146 |
<svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2"> |
| 147 |
<rect x="3" y="4" width="18" height="18" rx="2" ry="2"/> |
| 148 |
<line x1="16" y1="2" x2="16" y2="6"/> |
| 149 |
<line x1="8" y1="2" x2="8" y2="6"/> |
| 150 |
<line x1="3" y1="10" x2="21" y2="10"/> |
| 151 |
</svg> |
| 152 |
<?php echo get_the_modified_date(); ?> |
| 153 |
</span> |
| 154 |
<?php |
| 155 |
$reading_time = ceil(str_word_count(strip_tags(get_the_content())) / 200); |
| 156 |
?> |
| 157 |
<span class="kng-docs-article-reading"> |
| 158 |
<svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2"> |
| 159 |
<circle cx="12" cy="12" r="10"/> |
| 160 |
<polyline points="12 6 12 12 16 14"/> |
| 161 |
</svg> |
| 162 |
<?php printf(esc_html(_n('%d min read', '%d min read', $reading_time, 'king-addons')), $reading_time); ?> |
| 163 |
</span> |
| 164 |
</div> |
| 165 |
</header> |
| 166 |
|
| 167 |
<?php if ($toc_enabled): ?> |
| 168 |
<!-- Table of Contents (generated by JS) --> |
| 169 |
<nav class="kng-docs-toc" id="kng-docs-toc" style="display: none;"> |
| 170 |
<h4 class="kng-docs-toc-title"> |
| 171 |
<svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2"> |
| 172 |
<line x1="3" y1="6" x2="21" y2="6"/> |
| 173 |
<line x1="3" y1="12" x2="21" y2="12"/> |
| 174 |
<line x1="3" y1="18" x2="21" y2="18"/> |
| 175 |
</svg> |
| 176 |
<?php esc_html_e('On this page', 'king-addons'); ?> |
| 177 |
</h4> |
| 178 |
<ul class="kng-docs-toc-list"></ul> |
| 179 |
</nav> |
| 180 |
<?php endif; ?> |
| 181 |
|
| 182 |
<div class="kng-docs-article-content" data-toc-headings="<?php echo esc_attr($options['toc_headings'] ?? 'h2,h3'); ?>"> |
| 183 |
<?php the_content(); ?> |
| 184 |
</div> |
| 185 |
|
| 186 |
<?php if ($feedback_enabled): ?> |
| 187 |
<!-- Feedback Section --> |
| 188 |
<div class="kng-docs-feedback" data-doc-id="<?php echo esc_attr($doc_id); ?>"> |
| 189 |
<p class="kng-docs-feedback-question"> |
| 190 |
<?php echo esc_html($options['feedback_question'] ?? __('Was this article helpful?', 'king-addons')); ?> |
| 191 |
</p> |
| 192 |
<div class="kng-docs-feedback-buttons"> |
| 193 |
<button type="button" class="kng-docs-feedback-btn kng-docs-feedback-yes" data-value="helpful"> |
| 194 |
<svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2"> |
| 195 |
<path d="M14 9V5a3 3 0 00-3-3l-4 9v11h11.28a2 2 0 002-1.7l1.38-9a2 2 0 00-2-2.3zM7 22H4a2 2 0 01-2-2v-7a2 2 0 012-2h3"/> |
| 196 |
</svg> |
| 197 |
<?php esc_html_e('Yes', 'king-addons'); ?> |
| 198 |
</button> |
| 199 |
<button type="button" class="kng-docs-feedback-btn kng-docs-feedback-no" data-value="not_helpful"> |
| 200 |
<svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2"> |
| 201 |
<path d="M10 15v4a3 3 0 003 3l4-9V2H5.72a2 2 0 00-2 1.7l-1.38 9a2 2 0 002 2.3zm7-13h2.67A2.31 2.31 0 0122 4v7a2.31 2.31 0 01-2.33 2H17"/> |
| 202 |
</svg> |
| 203 |
<?php esc_html_e('No', 'king-addons'); ?> |
| 204 |
</button> |
| 205 |
</div> |
| 206 |
<div class="kng-docs-feedback-thanks" style="display: none;"> |
| 207 |
<svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2"> |
| 208 |
<path d="M22 11.08V12a10 10 0 11-5.93-9.14"/> |
| 209 |
<polyline points="22 4 12 14.01 9 11.01"/> |
| 210 |
</svg> |
| 211 |
<?php esc_html_e('Thank you for your feedback!', 'king-addons'); ?> |
| 212 |
</div> |
| 213 |
</div> |
| 214 |
<?php endif; ?> |
| 215 |
|
| 216 |
<?php if (!empty($related_docs)): ?> |
| 217 |
<!-- Related Articles --> |
| 218 |
<div class="kng-docs-related"> |
| 219 |
<h3 class="kng-docs-related-title"><?php esc_html_e('Related Articles', 'king-addons'); ?></h3> |
| 220 |
<div class="kng-docs-related-grid"> |
| 221 |
<?php foreach ($related_docs as $related): ?> |
| 222 |
<a href="<?php echo esc_url(get_permalink($related)); ?>" class="kng-docs-related-item"> |
| 223 |
<span class="kng-docs-related-item-title"><?php echo esc_html($related->post_title); ?></span> |
| 224 |
<svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2"><path d="M9 18l6-6-6-6"/></svg> |
| 225 |
</a> |
| 226 |
<?php endforeach; ?> |
| 227 |
</div> |
| 228 |
</div> |
| 229 |
<?php endif; ?> |
| 230 |
|
| 231 |
<?php if (!empty($navigation)): ?> |
| 232 |
<!-- Article Navigation --> |
| 233 |
<nav class="kng-docs-navigation"> |
| 234 |
<?php if (!empty($navigation['prev'])): ?> |
| 235 |
<a href="<?php echo esc_url(get_permalink($navigation['prev'])); ?>" class="kng-docs-nav-item kng-docs-nav-prev"> |
| 236 |
<svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2"><path d="M15 18l-6-6 6-6"/></svg> |
| 237 |
<span> |
| 238 |
<span class="kng-docs-nav-label"><?php esc_html_e('Previous', 'king-addons'); ?></span> |
| 239 |
<span class="kng-docs-nav-title"><?php echo esc_html($navigation['prev']->post_title); ?></span> |
| 240 |
</span> |
| 241 |
</a> |
| 242 |
<?php else: ?> |
| 243 |
<span></span> |
| 244 |
<?php endif; ?> |
| 245 |
|
| 246 |
<?php if (!empty($navigation['next'])): ?> |
| 247 |
<a href="<?php echo esc_url(get_permalink($navigation['next'])); ?>" class="kng-docs-nav-item kng-docs-nav-next"> |
| 248 |
<span> |
| 249 |
<span class="kng-docs-nav-label"><?php esc_html_e('Next', 'king-addons'); ?></span> |
| 250 |
<span class="kng-docs-nav-title"><?php echo esc_html($navigation['next']->post_title); ?></span> |
| 251 |
</span> |
| 252 |
<svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2"><path d="M9 18l6-6-6-6"/></svg> |
| 253 |
</a> |
| 254 |
<?php endif; ?> |
| 255 |
</nav> |
| 256 |
<?php endif; ?> |
| 257 |
</article> |
| 258 |
|
| 259 |
<?php if ($toc_enabled && !$sidebar_enabled && !empty($options['toc_sticky'])): ?> |
| 260 |
<!-- Floating TOC (when no sidebar) --> |
| 261 |
<aside class="kng-docs-toc-floating is-sticky"> |
| 262 |
<div class="kng-docs-toc-floating-inner"> |
| 263 |
<h4 class="kng-docs-toc-title"><?php esc_html_e('On this page', 'king-addons'); ?></h4> |
| 264 |
<ul class="kng-docs-toc-list kng-docs-toc-floating-list"></ul> |
| 265 |
</div> |
| 266 |
</aside> |
| 267 |
<?php endif; ?> |
| 268 |
</div> |
| 269 |
</div> |
| 270 |
</div> |
| 271 |
|
| 272 |
<script> |
| 273 |
(function() { |
| 274 |
// TOC generation |
| 275 |
var content = document.querySelector('.kng-docs-article-content'); |
| 276 |
var toc = document.getElementById('kng-docs-toc'); |
| 277 |
var floatingToc = document.querySelector('.kng-docs-toc-floating-list'); |
| 278 |
|
| 279 |
if (content && (toc || floatingToc)) { |
| 280 |
var headings = content.dataset.tocHeadings || 'h2,h3'; |
| 281 |
var elements = content.querySelectorAll(headings); |
| 282 |
|
| 283 |
if (elements.length > 0) { |
| 284 |
var list = ''; |
| 285 |
elements.forEach(function(el, index) { |
| 286 |
var id = 'toc-' + index; |
| 287 |
el.id = id; |
| 288 |
var level = el.tagName.toLowerCase(); |
| 289 |
list += '<li class="kng-docs-toc-item kng-docs-toc-' + level + '">'; |
| 290 |
list += '<a href="#' + id + '">' + el.textContent + '</a>'; |
| 291 |
list += '</li>'; |
| 292 |
}); |
| 293 |
|
| 294 |
if (toc) { |
| 295 |
toc.querySelector('.kng-docs-toc-list').innerHTML = list; |
| 296 |
toc.style.display = ''; |
| 297 |
} |
| 298 |
if (floatingToc) { |
| 299 |
floatingToc.innerHTML = list; |
| 300 |
} |
| 301 |
} |
| 302 |
} |
| 303 |
|
| 304 |
// Smooth scroll |
| 305 |
document.querySelectorAll('.kng-docs-toc-list a').forEach(function(link) { |
| 306 |
link.addEventListener('click', function(e) { |
| 307 |
e.preventDefault(); |
| 308 |
var target = document.querySelector(this.getAttribute('href')); |
| 309 |
if (target) { |
| 310 |
target.scrollIntoView({ behavior: 'smooth', block: 'start' }); |
| 311 |
} |
| 312 |
}); |
| 313 |
}); |
| 314 |
|
| 315 |
// Feedback |
| 316 |
var feedback = document.querySelector('.kng-docs-feedback'); |
| 317 |
if (feedback) { |
| 318 |
feedback.querySelectorAll('.kng-docs-feedback-btn').forEach(function(btn) { |
| 319 |
btn.addEventListener('click', function() { |
| 320 |
var docId = feedback.dataset.docId; |
| 321 |
var value = this.dataset.value; |
| 322 |
|
| 323 |
fetch('<?php echo esc_url(admin_url('admin-ajax.php')); ?>', { |
| 324 |
method: 'POST', |
| 325 |
headers: {'Content-Type': 'application/x-www-form-urlencoded'}, |
| 326 |
body: 'action=king_addons_docs_feedback&doc_id=' + docId + '&feedback=' + value + '&nonce=<?php echo wp_create_nonce('king_addons_docs_feedback'); ?>' |
| 327 |
}); |
| 328 |
|
| 329 |
feedback.querySelector('.kng-docs-feedback-buttons').style.display = 'none'; |
| 330 |
feedback.querySelector('.kng-docs-feedback-question').style.display = 'none'; |
| 331 |
feedback.querySelector('.kng-docs-feedback-thanks').style.display = ''; |
| 332 |
}); |
| 333 |
}); |
| 334 |
} |
| 335 |
})(); |
| 336 |
</script> |
| 337 |
|
| 338 |
<?php get_footer(); ?> |
| 339 |
|