瀏覽代碼

Dynamic menu rework

Md Mozahidur Rahman 1 年之前
父節點
當前提交
2e7021a88a
共有 2 個文件被更改,包括 55 次插入55 次删除
  1. 51 51
      functions.php
  2. 4 4
      inc/acf-json/group_648ad0b0ca222.json

+ 51 - 51
functions.php

@@ -260,6 +260,28 @@ function uiu_acf_update_user_id($value, $post_id, $field)
 add_filter('acf/update_value/name=employeeid', 'uiu_acf_update_user_id', 10, 3);
 
 
+/**
+ * Make theme option page field value available via REST API
+ */
+
+
+function theme_options_route_menu()
+{
+	return get_field('menu_rich_contents', 'option');
+}
+
+add_action("rest_api_init", function () {
+	register_rest_route("options", "/menu", [
+		"methods" => "GET",
+		"callback" => "theme_options_route_menu",
+	]);
+});
+
+add_action('rest_api_init', function () {
+	header("Access-Control-Allow-Origin: *");
+});
+
+
 /**
  * Custom Walker class to add extra element to sub-menu ul.
  */
@@ -272,7 +294,7 @@ class Custom_Walker_Nav_Menu extends Walker_Nav_Menu
 
 
 		parent::start_lvl($output, $depth, $args);
-		$output .= '<div class="container"><div class="extra-item col-breaker">
+		$output .= '<div class="container"><div class="sub-menu-feature">
                       <img class="menu_feature_image" src="../wp-content/themes/uiu-cse/img/menu-background.jpg" alt="">
                       <div class="heading-text menu_title">
                         Research
@@ -280,13 +302,13 @@ class Custom_Walker_Nav_Menu extends Walker_Nav_Menu
                       <div class="text menu_description">
                         We collect personal information from you so we can provide investment services to you.
                       </div>
-                    </div>';
+                    </div><div class="sub-menu-link-container">';
 	}
 
 	public function end_lvl(&$output, $depth = 0, $args = array())
 	{
 		// Add your extra element here.
-		$output .= '</div>';
+		$output .= '</div></div>';
 		parent::end_lvl($output, $depth, $args);
 	}
 }
@@ -303,51 +325,29 @@ add_filter('wp_nav_menu_args', 'custom_menu_walker');
  * Insert_extra_element_to_submenu
  */
 
-function insert_extra_element_to_submenu($matches)
-{
-	$sub_menu_ul = $matches[0];
-	$extra_element = '<div class="extra-item col-breaker">
-                      <img class="menu_feature_image" src="../wp-content/themes/uiu-cse/img/menu-background.jpg" alt="">
-                      <div class="heading-text menu_title">
-                        Research
-                      </div>
-                      <div class="text menu_description">
-                        We collect personal information from you so we can provide investment services to you.
-                      </div>
-                    </div>';
-	$sub_menu_ul .= $extra_element;
-	return $sub_menu_ul;
-}
-
-
-function custom_add_extra_element_to_submenu($nav_menu, $args)
-{
-	// Find all sub-menu ul elements and add the extra element after each one.
-	$nav_menu = preg_replace_callback('/(<ul\s*class="sub-menu[^"]*">)/', 'insert_extra_element_to_submenu', $nav_menu);
-
-	return $nav_menu;
-}
-
-// add_filter('wp_nav_menu', 'custom_add_extra_element_to_submenu', 10, 2);
-
-
-/**
- * Make theme option page field value available via REST API
- */
-
-
-function theme_options_route_menu()
-{
-	return get_field('menu_rich_contents', 'option');
-}
-
-add_action("rest_api_init", function () {
-	register_rest_route("options", "/menu", [
-		"methods" => "GET",
-		"callback" => "theme_options_route_menu",
-	]);
-});
-
-add_action('rest_api_init', function () {
-	header("Access-Control-Allow-Origin: *");
-});
+// function insert_extra_element_to_submenu($matches)
+// {
+// 	$sub_menu_ul = $matches[0];
+// 	$extra_element = '<div class="extra-item col-breaker">
+//                       <img class="menu_feature_image" src="../wp-content/themes/uiu-cse/img/menu-background.jpg" alt="">
+//                       <div class="heading-text menu_title">
+//                         Research
+//                       </div>
+//                       <div class="text menu_description">
+//                         We collect personal information from you so we can provide investment services to you.
+//                       </div>
+//                     </div>';
+// 	$sub_menu_ul .= $extra_element;
+// 	return $sub_menu_ul;
+// }
+
+
+// function custom_add_extra_element_to_submenu($nav_menu, $args)
+// {
+// 	// Find all sub-menu ul elements and add the extra element after each one.
+// 	$nav_menu = preg_replace_callback('/(<ul\s*class="sub-menu[^"]*">)/', 'insert_extra_element_to_submenu', $nav_menu);
+
+// 	return $nav_menu;
+// }
+
+// add_filter('wp_nav_menu', 'custom_add_extra_element_to_submenu', 10, 2);

+ 4 - 4
inc/acf-json/group_648ad0b0ca222.json

@@ -50,7 +50,7 @@
                 "class": "",
                 "id": ""
             },
-            "layout": "row",
+            "layout": "table",
             "pagination": 0,
             "min": 0,
             "max": 0,
@@ -60,8 +60,8 @@
             "sub_fields": [
                 {
                     "key": "field_648ad0b1a815d",
-                    "label": "Menu Parent Class",
-                    "name": "menu_parent_class",
+                    "label": "Parent Navigation Label",
+                    "name": "parent_navigation_label",
                     "aria-label": "",
                     "type": "text",
                     "instructions": "",
@@ -168,5 +168,5 @@
     "active": true,
     "description": "",
     "show_in_rest": 1,
-    "modified": 1686834614
+    "modified": 1687070795
 }