diff options
| author | tradam <[email protected]> | 2025-11-18 23:37:40 +0000 |
|---|---|---|
| committer | tradam <[email protected]> | 2025-11-18 23:37:40 +0000 |
| commit | 072f012398e448682f6d1cb0d981bdbb5e46263c (patch) | |
| tree | 388689a338820c60ad93ff0c61fcaba258773943 /plugins | |
| parent | 5ec6e44935e7c979fd718d6aa2c7a5308da0ee54 (diff) | |
| download | malcz-wordpress-theme-dev.tar.gz malcz-wordpress-theme-dev.zip | |
progressdev
Diffstat (limited to 'plugins')
| -rw-r--r-- | plugins/class-wp-picocss-navwalker.php | 57 |
1 files changed, 57 insertions, 0 deletions
diff --git a/plugins/class-wp-picocss-navwalker.php b/plugins/class-wp-picocss-navwalker.php new file mode 100644 index 0000000..1cf617d --- /dev/null +++ b/plugins/class-wp-picocss-navwalker.php @@ -0,0 +1,57 @@ +<?php +class Pico_Details_Nav_Walker extends Walker_Nav_Menu { + + // Only called for submenus + public function start_lvl( &$output, $depth = 0, $args = array() ) { + $indent = str_repeat("\t", $depth); + $output .= "\n$indent<ul class=\"dropdown-menu\">\n"; + } + + public function end_lvl( &$output, $depth = 0, $args = array() ) { + $indent = str_repeat("\t", $depth); + $output .= "$indent</ul>\n"; + } + + public function start_el( &$output, $item, $depth = 0, $args = array(), $id = 0 ) { + $has_children = in_array('menu-item-has-children', $item->classes); + + // Top-level item with children -> use <details> + if ($depth === 0 && $has_children) { + $output .= '<details class="dropdown">'; + $output .= '<summary role="button" class="outline contrast" data-theme="dark">' . esc_html($item->title) . '</summary>'; + } + // Top-level item WITHOUT children -> <li> with data-theme="dark" + elseif ($depth === 0 && !$has_children) { + $atts = []; + $atts['href'] = !empty($item->url) ? esc_url($item->url) : '#'; + $attributes = ''; + foreach ($atts as $attr => $value) { + $attributes .= " $attr=\"$value\""; + } + + $output .= '<li data-theme="dark"><a' . $attributes . ' class="contrast">' . esc_html($item->title) . '</a>'; + } + // Submenu items -> normal <li> without data-theme + else { + $atts = []; + $atts['href'] = !empty($item->url) ? esc_url($item->url) : '#'; + $attributes = ''; + foreach ($atts as $attr => $value) { + $attributes .= " $attr=\"$value\""; + } + + $output .= '<li><a' . $attributes . ' class="contrast">' . esc_html($item->title) . '</a>'; + } + } + + + public function end_el( &$output, $item, $depth = 0, $args = array() ) { + $has_children = in_array('menu-item-has-children', $item->classes); + + if ($depth === 0 && $has_children) { + $output .= '</details>'; + } else { + $output .= '</li>'; + } + } +} |
