From 79cf48fa181ed9dbca7ad0ed356bcad58d1af972 Mon Sep 17 00:00:00 2001 From: Antoine M Date: Tue, 27 Jan 2026 14:01:30 +0100 Subject: [PATCH] =?UTF-8?q?FEATURE=20Ajout=20d'ic=C3=B4nes=20de=20page=20a?= =?UTF-8?q?ux=20=C3=A9l=C3=A9ments=20de=20menu=20avec=20sous-menu?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- includes/navwalker.php | 14 ++++++++++++-- includes/nawalker_fction.php | 6 ++++-- 2 files changed, 16 insertions(+), 4 deletions(-) diff --git a/includes/navwalker.php b/includes/navwalker.php index 78865ae..a3cd02e 100644 --- a/includes/navwalker.php +++ b/includes/navwalker.php @@ -7,11 +7,21 @@ function wrap_parent_menu_item_buttons($output, $item, $depth, $args) { // #### MENU HOMEGRADE HEADER - if ($args->theme_location === "secondary" && in_array('menu-item-has-children', $item->classes, true)) { - + if ($args->theme_location === "secondary" && in_array('menu-item-has-children', $item->classes, true)) { $output = ''; } + if ($args->theme_location === "primary" && in_array('menu-item-has-children', $item->classes, true)) { + $page_icon = get_field('page_icon', $item->object_id) ?? null; + $icon = isset($page_icon) && is_array($page_icon) && !empty($page_icon['url']) ? '' : ''; + $output = ''; + } + // write_log($item->classes); + if ($args->theme_location === "primary" && !in_array('menu-item-has-children', $item->classes, true)) { + $page_icon = get_field('page_icon', $item->object_id) ?? null; + $icon = isset($page_icon) && is_array($page_icon) && !empty($page_icon['url']) ? '' : ''; + $output = '' . $icon . $item->title . ''; + } return $output; } add_filter('walker_nav_menu_start_el', 'wrap_parent_menu_item_buttons', 10, 4); diff --git a/includes/nawalker_fction.php b/includes/nawalker_fction.php index 1882ea1..2fa9795 100644 --- a/includes/nawalker_fction.php +++ b/includes/nawalker_fction.php @@ -7,9 +7,11 @@ function carhop_wrap_parent_menu_item_buttons($output, $item, $depth, $args) { if ($args->theme_location === "primary") { - $page_icon = get_field('page_icon', $item->object_id); + $page_icon = get_field('page_icon', $item->object_id) ?? null; + // $test = get_field('page_icon', 729); + // write_log($test); - if (isset($page_icon)) { + if (isset($page_icon) && is_array($page_icon) && !empty($page_icon['url'])) { $icon = ''; // Insérer l'icône à l'intérieur du lien (seulement la première occurrence) $output = preg_replace('/>/', '>' . $icon, $output, 1);