-
-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathsidebar-list.php
77 lines (73 loc) · 1.95 KB
/
sidebar-list.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
<?php
/**
* The sidebar for list pages
*
* @link https://developer.wordpress.org/themes/basics/template-files/#template-partials
*
* @package shiro
*/
// $args is data passed into the template, also we provide fallbacks in case they don't exist.
// phpcs:disable VariableAnalysis.CodeAnalysis.VariableAnalysis.UndefinedVariable
$nested = $args['nested'] ?? false;
$template_args = is_array( $args['template_args'] ?? false ) ? $args['template_args'] : get_post_meta( get_the_ID(), 'list', true );
// phpcs:enable
if ( empty( $template_args ) ) {
return;
}
?>
<?php if ( ! $nested ) : ?>
<nav
class="toc-nav"
data-backdrop="inactive"
data-dropdown="toc-nav"
data-dropdown-content=".toc"
data-dropdown-status="uninitialized"
data-dropdown-toggle=".toc__button"
data-sticky="false"
data-toggleable="yes"
data-trap="inactive"
data-visible="false"
>
<h2 class="toc__title screen-reader-text">
<?php esc_html_e( 'Table of Contents', 'shiro' ); ?>
</h2>
<button
aria-expanded="false"
class="toc__button"
hidden
>
<span class="btn-label-a11y">
<?php esc_html_e( 'Navigate within this page.', 'shiro' ); ?>
</span>
<span class="btn-label-active-item">
<?php
if ( empty( $template_args[0]['title'] ) ) {
esc_html_e( 'Toggle menu', 'shiro' );
} else {
echo esc_html( $template_args[0]['title'] );
}
?>
</span>
</button>
<ul class="table-of-contents toc">
<?php else : ?>
<ul class="toc__nested">
<?php endif; ?>
<?php
foreach ( $template_args as $i => $list_section ) :
$item_text = $list_section['title'] ?? $list_section['name'] ?? '';
$item_link = ( $list_section['slug'] ?? false ) ? '#' . $list_section['slug'] : '#section-' . ( $i + 1 );
if ( empty( $item_text ) ) {
continue;
}
?>
<li class="toc__item">
<a class="toc__link" href="<?php echo esc_url( $item_link ); ?>">
<?php echo esc_html( $item_text ); ?>
</a>
</li>
<?php endforeach; ?>
</ul>
<?php if ( ! $nested ) : ?>
</nav>
<?php endif; ?>