| 1 |
<?php |
| 2 |
/** |
| 3 |
* Template: Single Doc Article |
| 4 |
* |
| 5 |
* Apple Liquid-Glass design – breadcrumbs, sidebar, sticky TOC, content, |
| 6 |
* reactions, related articles, prev/next navigation. |
| 7 |
* |
| 8 |
* @package King_Addons |
| 9 |
*/ |
| 10 |
|
| 11 |
defined('ABSPATH') || exit; |
| 12 |
|
| 13 |
$ext = \King_Addons\Docs_KB::instance(); |
| 14 |
$options = $ext->get_options(); |
| 15 |
$mode = $options['dark_mode'] ?? 'auto'; |
| 16 |
$primary = $options['primary_color'] ?? '#0071e3'; |
| 17 |
|
| 18 |
$show_toc = !empty($options['toc_enabled']); |
| 19 |
$show_reading = !empty($options['reading_time']); |
| 20 |
$show_share = !empty($options['social_share']); |
| 21 |
$show_reactions = !empty($options['reactions_enabled']); |
| 22 |
|
| 23 |
/* ── Current article ── */ |
| 24 |
$post_id = get_the_ID(); |
| 25 |
$terms = get_the_terms($post_id, 'kng_doc_category'); |
| 26 |
$cat = ($terms && !is_wp_error($terms)) ? $terms[0] : null; |
| 27 |
$tags = get_the_terms($post_id, 'kng_doc_tag'); |
| 28 |
|
| 29 |
/* ── Sidebar: articles in same category ── */ |
| 30 |
$sidebar_posts = []; |
| 31 |
if ($cat) { |
| 32 |
$sidebar_posts = get_posts([ |
| 33 |
'post_type' => 'kng_doc', |
| 34 |
'posts_per_page' => 40, |
| 35 |
'tax_query' => [[ |
| 36 |
'taxonomy' => 'kng_doc_category', |
| 37 |
'terms' => $cat->term_id, |
| 38 |
]], |
| 39 |
'orderby' => 'menu_order', |
| 40 |
'order' => 'ASC', |
| 41 |
]); |
| 42 |
} |
| 43 |
|
| 44 |
/* ── Meta ── */ |
| 45 |
$views = (int) get_post_meta($post_id, '_kng_doc_views', true); |
| 46 |
$reading_time = $ext::estimate_reading_time(get_the_content()); |
| 47 |
|
| 48 |
/* ── Related ── */ |
| 49 |
$related = $ext->get_related_docs($post_id, 3); |
| 50 |
|
| 51 |
/* ── Prev / Next ── */ |
| 52 |
$nav = $ext->get_article_navigation($post_id); |
| 53 |
|
| 54 |
get_header(); |
| 55 |
?> |
| 56 |
|
| 57 |
<div class="kng-docs-page" |
| 58 |
data-kng-theme-mode="<?php echo esc_attr($mode); ?>" |
| 59 |
style="--kng-docs-primary:<?php echo esc_attr($primary); ?>; --kng-docs-icon-color:<?php echo esc_attr($primary); ?>;"> |
| 60 |
|
| 61 |
<div class="kng-docs-container"> |
| 62 |
|
| 63 |
<!-- ══════════════════════════════════════ |
| 64 |
BREADCRUMBS |
| 65 |
══════════════════════════════════════ --> |
| 66 |
<nav class="kng-docs-breadcrumbs" aria-label="<?php esc_attr_e('Breadcrumb', 'king-addons'); ?>"> |
| 67 |
<a href="<?php echo esc_url(get_post_type_archive_link('kng_doc')); ?>" class="kng-docs-breadcrumb-item"> |
| 68 |
<?php echo $ext->get_icon_svg('home'); ?> |
| 69 |
<?php esc_html_e('Docs', 'king-addons'); ?> |
| 70 |
</a> |
| 71 |
|
| 72 |
<?php if ($cat) : ?> |
| 73 |
<span class="kng-docs-breadcrumb-sep">/</span> |
| 74 |
<a href="<?php echo esc_url(get_term_link($cat)); ?>" class="kng-docs-breadcrumb-item"> |
| 75 |
<?php echo esc_html($cat->name); ?> |
| 76 |
</a> |
| 77 |
<?php endif; ?> |
| 78 |
|
| 79 |
<span class="kng-docs-breadcrumb-sep">/</span> |
| 80 |
<span class="kng-docs-breadcrumb-current"><?php the_title(); ?></span> |
| 81 |
</nav> |
| 82 |
|
| 83 |
<!-- ══════════════════════════════════════ |
| 84 |
3-COLUMN LAYOUT |
| 85 |
══════════════════════════════════════ --> |
| 86 |
<div class="kng-docs-single-layout <?php echo !empty($sidebar_posts) ? 'has-sidebar' : ''; ?> <?php echo $show_toc ? 'has-toc-aside' : ''; ?>"> |
| 87 |
|
| 88 |
<!-- ── Sidebar ── --> |
| 89 |
<?php if (!empty($sidebar_posts)) : ?> |
| 90 |
<aside class="kng-docs-sidebar is-sticky"> |
| 91 |
<div class="kng-docs-sidebar-inner"> |
| 92 |
<?php if ($cat) : ?> |
| 93 |
<h4 class="kng-docs-sidebar-title"><?php echo esc_html($cat->name); ?></h4> |
| 94 |
<?php endif; ?> |
| 95 |
|
| 96 |
<ul class="kng-docs-sidebar-list"> |
| 97 |
<?php foreach ($sidebar_posts as $sp) : ?> |
| 98 |
<li class="<?php echo $sp->ID === $post_id ? 'is-current' : ''; ?>"> |
| 99 |
<a href="<?php echo get_permalink($sp); ?>"> |
| 100 |
<?php echo esc_html($sp->post_title); ?> |
| 101 |
</a> |
| 102 |
</li> |
| 103 |
<?php endforeach; wp_reset_postdata(); ?> |
| 104 |
</ul> |
| 105 |
</div> |
| 106 |
</aside> |
| 107 |
<?php endif; ?> |
| 108 |
|
| 109 |
<!-- ── Main Article ── --> |
| 110 |
<article class="kng-docs-article"> |
| 111 |
|
| 112 |
<!-- Actions bar --> |
| 113 |
<div class="kng-docs-article-actions"> |
| 114 |
<button class="kng-docs-action-btn" onclick="window.print()" title="<?php esc_attr_e('Print', 'king-addons'); ?>"> |
| 115 |
<?php echo $ext->get_icon_svg('printer'); ?> |
| 116 |
</button> |
| 117 |
</div> |
| 118 |
|
| 119 |
<!-- Header --> |
| 120 |
<header class="kng-docs-article-header kng-docs-reveal"> |
| 121 |
<h1 class="kng-docs-article-title"><?php the_title(); ?></h1> |
| 122 |
|
| 123 |
<div class="kng-docs-article-meta"> |
| 124 |
<span> |
| 125 |
<?php echo $ext->get_icon_svg('calendar'); ?> |
| 126 |
<?php echo get_the_modified_date(); ?> |
| 127 |
</span> |
| 128 |
|
| 129 |
<?php if ($show_reading && $reading_time) : ?> |
| 130 |
<span> |
| 131 |
<?php echo $ext->get_icon_svg('clock'); ?> |
| 132 |
<?php echo esc_html($reading_time); ?> |
| 133 |
</span> |
| 134 |
<?php endif; ?> |
| 135 |
|
| 136 |
<?php if ($views) : ?> |
| 137 |
<span> |
| 138 |
<?php echo $ext->get_icon_svg('eye'); ?> |
| 139 |
<?php printf( |
| 140 |
esc_html(_n('%d view', '%d views', $views, 'king-addons')), |
| 141 |
$views |
| 142 |
); ?> |
| 143 |
</span> |
| 144 |
<?php endif; ?> |
| 145 |
</div> |
| 146 |
|
| 147 |
<?php if ($tags && !is_wp_error($tags)) : ?> |
| 148 |
<div class="kng-docs-article-tags"> |
| 149 |
<?php foreach ($tags as $tag) : ?> |
| 150 |
<a href="<?php echo esc_url(get_term_link($tag)); ?>" class="kng-docs-tag"> |
| 151 |
<?php echo esc_html($tag->name); ?> |
| 152 |
</a> |
| 153 |
<?php endforeach; ?> |
| 154 |
</div> |
| 155 |
<?php endif; ?> |
| 156 |
</header> |
| 157 |
|
| 158 |
<!-- TOC (inline, above content) --> |
| 159 |
<?php if ($show_toc) : ?> |
| 160 |
<div class="kng-docs-toc kng-docs-reveal"> |
| 161 |
<h4 class="kng-docs-toc-title"> |
| 162 |
<?php echo $ext->get_icon_svg('list'); ?> |
| 163 |
<?php esc_html_e('Table of Contents', 'king-addons'); ?> |
| 164 |
</h4> |
| 165 |
<ul class="kng-docs-toc-list"> |
| 166 |
<!-- populated by JS --> |
| 167 |
</ul> |
| 168 |
</div> |
| 169 |
<?php endif; ?> |
| 170 |
|
| 171 |
<!-- Content --> |
| 172 |
<div class="kng-docs-article-content kng-docs-reveal"> |
| 173 |
<?php the_content(); ?> |
| 174 |
</div> |
| 175 |
|
| 176 |
<!-- Social Share --> |
| 177 |
<?php if ($show_share) : ?> |
| 178 |
<div class="kng-docs-share"> |
| 179 |
<span class="kng-docs-share-label"><?php esc_html_e('Share', 'king-addons'); ?></span> |
| 180 |
|
| 181 |
<button class="kng-docs-share-btn" data-share="copy" title="<?php esc_attr_e('Copy link', 'king-addons'); ?>"> |
| 182 |
<?php echo $ext->get_icon_svg('link'); ?> |
| 183 |
</button> |
| 184 |
<button class="kng-docs-share-btn" data-share="twitter" title="Twitter"> |
| 185 |
<svg viewBox="0 0 24 24" fill="currentColor"><path d="M18.244 2.25h3.308l-7.227 8.26 8.502 11.24H16.17l-5.214-6.817L4.99 21.75H1.68l7.73-8.835L1.254 2.25H8.08l4.713 6.231zm-1.161 17.52h1.833L7.084 4.126H5.117z"/></svg> |
| 186 |
</button> |
| 187 |
<button class="kng-docs-share-btn" data-share="facebook" title="Facebook"> |
| 188 |
<svg viewBox="0 0 24 24" fill="currentColor"><path d="M24 12.073c0-6.627-5.373-12-12-12s-12 5.373-12 12c0 5.99 4.388 10.954 10.125 11.854v-8.385H7.078v-3.47h3.047V9.43c0-3.007 1.792-4.669 4.533-4.669 1.312 0 2.686.235 2.686.235v2.953H15.83c-1.491 0-1.956.925-1.956 1.874v2.25h3.328l-.532 3.47h-2.796v8.385C19.612 23.027 24 18.062 24 12.073z"/></svg> |
| 189 |
</button> |
| 190 |
<button class="kng-docs-share-btn" data-share="linkedin" title="LinkedIn"> |
| 191 |
<svg viewBox="0 0 24 24" fill="currentColor"><path d="M20.447 20.452h-3.554v-5.569c0-1.328-.027-3.037-1.852-3.037-1.853 0-2.136 1.445-2.136 2.939v5.667H9.351V9h3.414v1.561h.046c.477-.9 1.637-1.85 3.37-1.85 3.601 0 4.267 2.37 4.267 5.455v6.286zM5.337 7.433c-1.144 0-2.063-.926-2.063-2.065 0-1.138.92-2.063 2.063-2.063 1.14 0 2.064.925 2.064 2.063 0 1.139-.925 2.065-2.064 2.065zm1.782 13.019H3.555V9h3.564v11.452zM22.225 0H1.771C.792 0 0 .774 0 1.729v20.542C0 23.227.792 24 1.771 24h20.451C23.2 24 24 23.227 24 22.271V1.729C24 .774 23.2 0 22.222 0h.003z"/></svg> |
| 192 |
</button> |
| 193 |
</div> |
| 194 |
<?php endif; ?> |
| 195 |
|
| 196 |
<!-- Reactions --> |
| 197 |
<?php if ($show_reactions) : ?> |
| 198 |
<div class="kng-docs-reactions" data-post-id="<?php echo esc_attr($post_id); ?>"> |
| 199 |
<p class="kng-docs-reactions-question"> |
| 200 |
<?php esc_html_e('Was this article helpful?', 'king-addons'); ?> |
| 201 |
</p> |
| 202 |
<div class="kng-docs-reactions-buttons"> |
| 203 |
<button class="kng-docs-reaction-btn" data-reaction="happy"> |
| 204 |
<span class="kng-docs-reaction-emoji">😊</span> |
| 205 |
<?php esc_html_e('Helpful', 'king-addons'); ?> |
| 206 |
</button> |
| 207 |
<button class="kng-docs-reaction-btn" data-reaction="neutral"> |
| 208 |
<span class="kng-docs-reaction-emoji">😐</span> |
| 209 |
<?php esc_html_e('Somewhat', 'king-addons'); ?> |
| 210 |
</button> |
| 211 |
<button class="kng-docs-reaction-btn" data-reaction="sad"> |
| 212 |
<span class="kng-docs-reaction-emoji">😞</span> |
| 213 |
<?php esc_html_e('Not helpful', 'king-addons'); ?> |
| 214 |
</button> |
| 215 |
</div> |
| 216 |
<span class="kng-docs-reactions-thanks"> |
| 217 |
<svg fill="none" stroke="currentColor" stroke-width="2" viewBox="0 0 24 24"><path d="M20.84 4.61a5.5 5.5 0 0 0-7.78 0L12 5.67l-1.06-1.06a5.5 5.5 0 0 0-7.78 7.78l1.06 1.06L12 21.23l7.78-7.78 1.06-1.06a5.5 5.5 0 0 0 0-7.78z" stroke-linecap="round" stroke-linejoin="round"/></svg> |
| 218 |
<?php esc_html_e('Thank you for your feedback!', 'king-addons'); ?> |
| 219 |
</span> |
| 220 |
</div> |
| 221 |
<?php endif; ?> |
| 222 |
|
| 223 |
<!-- Related articles --> |
| 224 |
<?php if (!empty($related)) : ?> |
| 225 |
<div class="kng-docs-related kng-docs-reveal"> |
| 226 |
<h3 class="kng-docs-related-title"><?php esc_html_e('Related Articles', 'king-addons'); ?></h3> |
| 227 |
<div class="kng-docs-related-grid"> |
| 228 |
<?php foreach ($related as $rel) : ?> |
| 229 |
<a href="<?php echo esc_url($rel['url']); ?>" class="kng-docs-related-item"> |
| 230 |
<?php echo esc_html($rel['title']); ?> |
| 231 |
<svg fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" viewBox="0 0 24 24"><path d="m9 18 6-6-6-6"/></svg> |
| 232 |
</a> |
| 233 |
<?php endforeach; ?> |
| 234 |
</div> |
| 235 |
</div> |
| 236 |
<?php endif; ?> |
| 237 |
|
| 238 |
<!-- Prev / Next --> |
| 239 |
<?php if ($nav['prev'] || $nav['next']) : ?> |
| 240 |
<nav class="kng-docs-navigation kng-docs-reveal"> |
| 241 |
<?php if ($nav['prev']) : ?> |
| 242 |
<a href="<?php echo esc_url($nav['prev']['url']); ?>" class="kng-docs-nav-item kng-docs-nav-prev"> |
| 243 |
<svg fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" viewBox="0 0 24 24"><path d="m15 18-6-6 6-6"/></svg> |
| 244 |
<span> |
| 245 |
<span class="kng-docs-nav-label"><?php esc_html_e('Previous', 'king-addons'); ?></span> |
| 246 |
<span class="kng-docs-nav-title"><?php echo esc_html($nav['prev']['title']); ?></span> |
| 247 |
</span> |
| 248 |
</a> |
| 249 |
<?php else : ?> |
| 250 |
<span></span> |
| 251 |
<?php endif; ?> |
| 252 |
|
| 253 |
<?php if ($nav['next']) : ?> |
| 254 |
<a href="<?php echo esc_url($nav['next']['url']); ?>" class="kng-docs-nav-item kng-docs-nav-next"> |
| 255 |
<span> |
| 256 |
<span class="kng-docs-nav-label"><?php esc_html_e('Next', 'king-addons'); ?></span> |
| 257 |
<span class="kng-docs-nav-title"><?php echo esc_html($nav['next']['title']); ?></span> |
| 258 |
</span> |
| 259 |
<svg fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" viewBox="0 0 24 24"><path d="m9 18 6-6-6-6"/></svg> |
| 260 |
</a> |
| 261 |
<?php endif; ?> |
| 262 |
</nav> |
| 263 |
<?php endif; ?> |
| 264 |
|
| 265 |
</article> |
| 266 |
|
| 267 |
<!-- ── Floating TOC aside (right column) ── --> |
| 268 |
<?php if ($show_toc) : ?> |
| 269 |
<aside class="kng-docs-toc-floating is-sticky"> |
| 270 |
<div class="kng-docs-toc-floating-inner"> |
| 271 |
<h4 class="kng-docs-toc-title"> |
| 272 |
<?php esc_html_e('On this page', 'king-addons'); ?> |
| 273 |
</h4> |
| 274 |
<ul class="kng-docs-toc-list kng-docs-toc-floating-list"> |
| 275 |
<!-- populated by JS --> |
| 276 |
</ul> |
| 277 |
</div> |
| 278 |
</aside> |
| 279 |
<?php endif; ?> |
| 280 |
|
| 281 |
</div> |
| 282 |
</div> |
| 283 |
</div> |
| 284 |
|
| 285 |
<?php get_footer(); ?> |
| 286 |
|