Contents
All sub-menu items need the number “2” as value for the parent_id. The parent_id for each main menu item is a “0” (zero). In the following code block I create a database result set and I add the value into a multi-dimensional arrays: $parent_menu and $sub_menu
The menu items are in the arrangement of $items [PARENT ID] [ITEM ID] = MENU ITEM. Close the database connection. I can hear angry trolls screaming “so stupid and dangerous to use an infinite while loop”. I agree, the more deeply nested the menu is, the slower and more complex this becomes. There is also a risk of getting into an infinite loop.
How to call a menu File with PHP and CSS?
This menu css uses a technique popularly known as “matching classes” to target the menu item of the current/active page. Taking this further into the realms of PHP, you can use php to do this by adding a current class to the menu item.
How to create a dynamic menu in PHP?
The creation of a dynamic menu with a nested un-ordered list without using any JavaScript code is sometimes a problem because the script needs to “remember” the values, sub values and also the query string from previous clicked links. In this tutorial I will explain how to create a dynamic navigation menu using PHP and MySQ.
You could merge items from one menu into another using a wp_nav_menu_objects filter. You’d need to know the ID of the menu you wanted to merge in, and the ID of the menu item which you wanted the merged items to be a child of. Then you could just get the menu items, set their parent menu item and merge them with the parent menu. E.g.
How to put HTML into a PHP include file?
Make a copy of the .html file and give the copy a .php suffix. Put comment marks around the HTML that is to go in a PHP include file. Like this: Then cut the text from between the comment marks and paste it into a new file with a .php suffix.